I am trying to use properties from a .properties
file, but it doesn\'t seem to work.
Here is my code:
@Service(\"ServiceFTP\")
@Transact
In my case, I was careless while merging the application.yml file, and I've unnecessary indented my properties to the right.
I've indented it like this:
spring:
application:
name: applicationName
............................
myProperties:
property1: property1value
While the code expected it to be like this:
spring:
application:
name: applicationName
.............................
myProperties:
property1: property1value
My solution was to add a space between the $ and the {.
For example:
@Value("${project.ftp.adresse}")
becomes
@Value("$ {project.ftp.adresse}")
This Issue occurs if the application is unable to access the some_file_name.properties file.Make sure that the properties file is placed under resources folder in spring.
Trouble shooting Steps
1: Add the properties file under the resource folder.
2: If you don't have a resource folder. Create one by navigating new by Right click on the project new > Source Folder, name it as resource and place your properties file under it.
For annotation based Implementation
Add @PropertySource(ignoreResourceNotFound = true, value = "classpath:some_file_name.properties")
//Add it before using the place holder
Example:
Assignment1Controller.Java
@PropertySource(ignoreResourceNotFound = true, value = "classpath:assignment1.properties")
@RestController
public class Assignment1Controller {
// @Autowired
// Assignment1Services assignment1Services;
@Value("${app.title}")
private String appTitle;
@RequestMapping(value = "/hello")
public String getValues() {
return appTitle;
}
}
assignment1.properties
app.title=Learning Spring
Deleting or corrupting the pom.xml file can cause this error.
You can also try default values. spring-value-annotation
Default values can be provided for properties that might not be defined. In this example the value “some default” will be injected:
@Value("${unknown.param:some default}")
private String someDefault;
If the same property is defined as a system property and in the properties file, then the system property would be applied.
I got the same error in my microservice project.The property itself missed in my yml file.So I added property name and value that resolves my problem