Issue
I am using Spring boot 2.5.4. I have written web application. Now i am facing issue with application.properties file variables. If i am changing existing value, In code old value is been read, newly defined object is not coming.
Find the below application.properties file
spring.datasource.url=jdbc:mysql://XXXXXXXXXXX:3306/test
spring.datasource.username=user
spring.datasource.password=XXXXXXXXXXXXXXXX
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
# Config Variables
ml.url=https://google.com/ml/entities
main.url=https://xxxx.com/staging/mainfile
and application config java file
@Component
public class ApplicationConfig {
@Value("${ml.url}")
public String mlurl;
@Value("${main.url}")
public String mainurl;
@PostConstruct
public void initThat(){
that = this;
}
}
reading variable in code as
@RequestMapping("/readfile")
@RestController
public class AppointmentResource {
private static Logger S_LOGGER = LogManager.getLogger( AppointmentResource.class );
@Autowired
private ApplicationConfig applicationConfig;
@GetMapping(value = "/websiteUrl",produces = MediaType.APPLICATION_JSON_VALUE)
public String getProduct() {
String websiteUrl = applicationConfig.mlurl;
S_LOGGER.info("website url is " + websiteUrl);
return websiteUrl;
}
}
After compiling for few times. Then i changes ml.url to https://google.com/prod/entities/test
but in code still i am getting as https://google.com/ml/entities
.
Can anyone help in getting latest changes from application.properties
I am struck here. Help
Solution
I fixed it. It was picking from the folder config. which i created for different environments
Answered By - vtustudent
Answer Checked By - David Marino (JavaFixing Volunteer)