spring boot does not load application.properties

Generate the eclipse project through mvn eclipse:eclipse, after importing it into eclipse, after starting SpringApplication.run, the system cannot find the home page, the database connection url is empty, etc. After careful inquiry, it is found that all the configuration items configured in application.properties are all Not loaded by spring.

After testing, it was found that loading through mvn spring-boot:run is normal.

application.properties is configured as follows:

 

# SPRING MVC
spring.view.suffix=.jsp
spring.view.prefix=/WEB-INF/views/

# SOLR
solr.host=http://192.168.56.11:8983/sol 

 

 The code using the configuration item is as follows:

@Configuration
@EnableSolrRepositories(basePackages = { "org.springframework.data.solr.showcase.product" })

public class SearchContext {

    @Bean
    public SolrServer solrServer(@Value("${solr.host}") String solrHost) {
        return new HttpSolrServer(solrHost);
    }

//  @Bean
//  public SolrServer solrServer(@Value("http://192.168.56.11:8983/solr") String solrHost) {
//      return new HttpSolrServer(solrHost);
//  }

    @Bean
    public SolrServerFactory solrServerFactory(SolrServer solrServer) {
        return new MulticoreSolrServerFactory(solrServer);
    }

    @Bean
    public SolrTemplate solrTemplate(SolrServerFactory solrServerFactory) {
        return new SolrTemplate(solrServerFactory);
    }

}

 application.properties is kept under src/main/resources.

 

After online query and analysis, it was found that the eclipse configuration source code excludes filtered out application.properties or application.yml. The specific location is: Project Properties --> Java Build Path --> Source(tab) --> Source folders on build path: [Exclusion section]

 

**/application.properties

 After removing this configuration, restart SpringApplication.run and the loading is successful!

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326612348&siteId=291194637