![](/img/trans.png)
[英]Spring boot shows 'can not be resolved' even if the dependency exists in classpath
[英]Spring Boot can't find classpath property from dependency module
我目前有一个Spring Boot应用程序,它依赖于Java模块。 该Java模块具有一些classpath属性。 当我通过Spring Boot应用程序中的Java模块@Autowired一个bean并使用@Bean批注定义该bean,然后运行Spring Boot应用程序时,它将抛出错误。
引发错误:
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?
Java模块中定义的属性
src/main/resources/myproject-context.xml
<util:properties id="myClassPathProperties" location="classpath:myproject.properties" />
Java模块中的属性用法
@Value("#{myClassPathProperties['property.x']}")
public void setClassPathProperty(String x) {
this.x = x;
}
Spring Boot应用程序中的Bean定义
@Bean (name = "mailSubscriptionDao")
public MyService getMyService() {
return new MyServiceImpl();
}
尝试让整个属性对象注入
@Autowired
Properties myClassPathProperties;
如果这可行,则说明您已正确加载了myproject-context.xml。 比起调试器,您还可以查看是否存在名称为“ property.x”的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.