Could not resolve placeholder in string value

后端 未结 11 1574
故里飘歌
故里飘歌 2020-12-01 01:00

I am trying to use properties from a .properties file, but it doesn\'t seem to work.

Here is my code:

@Service(\"ServiceFTP\")
@Transact         


        
11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 01:33

    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
    

提交回复
热议问题