简体   繁体   中英

Spring Boot can't find classpath property from dependency module

I currently have a Spring Boot application with a dependency to a Java module. This Java module has some classpath properties. When I @Autowired a bean from the Java module in my Spring Boot application and define this bean with a @Bean annotation and then run the Spring Boot application it will throw errors.

Error thrown:


2017-02-07 12:16:03.188  WARN 17620 --- [on(4)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : 
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyService': Unsatisfied dependency expressed through method 'setClassPathProperty' parameter 0; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'myClassPathProperties' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?

Property defined in Java Module

src/main/resources/myproject-context.xml
<util:properties id="myClassPathProperties" location="classpath:myproject.properties" />

Property usage in Java Module

@Value("#{myClassPathProperties['property.x']}")
public void setClassPathProperty(String x) {
    this.x = x;
}

Bean definition in Spring Boot application

@Bean (name = "mailSubscriptionDao")
public MyService getMyService() {
    return new MyServiceImpl();
}

Try to get the whole properties object injected

@Autowired    
Properties myClassPathProperties;

If this works, you know you have loaded myproject-context.xml correctly. Than you can also have a look with the debugger, whether a property with name 'property.x' exists or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM