Can't access application.properties file

落花浮王杯 提交于 2020-01-06 07:55:07

问题


I have multiple projects in which I am trying to read application.properties file from one particular project. There's one web application which I am deploying on tomcat. I want to use application.properties from another project.

I tried to import appconfig.java from that project to webAppconfig.java.

application.properties file in 1st project src/main/resources/application.properties contains driver=org.postgresql.Driver

1st project : Appconfig.java

@Configuration
@PropertySource("classpath:application.properties")
public class Appconfig{

@Value("${driver}")
private String test;
}

2nd project : WebAppconfig.java

@Import(Appconfig.java)
public class WebAppconfig{

}

I was expecting test=org.postgresql.Driver but I am getting exception as key "driver" not found.

If I change application.properties to something.properties, it works.

I tried following ways:

a)

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
  return new PropertySourcesPlaceholderConfigurer();
 }

b) tried changing in build path as included, excluded as shown in image

c)I tried autowiring environment as well.but is didn't work.. I debugged environment variable ..under property sources.it shows{spring.application.name="project 2 name"}

来源:https://stackoverflow.com/questions/54141518/cant-access-application-properties-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!