标题翻译
Inject property into applicationContext.xml as value (spring boot 2.2)
问题
我正尝试将一个属性注入到我的 Spring Boot 项目的 applicationContext.xml 文件中:
应用程序文件:
@SpringBootApplication
@PropertySource("classpath:navi.properties") // <== 在此处进行注入
@ImportResource({"classpath*:applicationContext.xml"}) // <== 加载 xml 设置文件
public class CApplication {
public static void main(String[] args) {
SpringApplication.run(CApplication.class, args);
}
}
如您所见,这里没有什么花哨的内容... 在我的 src/main/resources/navi.properties 文件中:
USER_INFO_CLS=jp.co.xxx.yyy.fw.service.UserInfoService
在我的 `applicationContext.xml` 中,我正在尝试注入这个值:
<bean id="userInfoService" class="${USER_INFO_CLS}"/>
但是运行 `./mvnw spring-boot:run` 后返回以下错误:
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [${USER_INFO_CLS}] for bean with name 'userInfoService' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: ${USER_INFO_CLS}
我阅读了许多相关文章(例如 [这篇][1]),听起来不错...
谢谢
[1]: https://www.baeldung.com/configuration-properties-in-spring-boot
英文翻译
I am trying to inject a property into my applicationContext.xml file in my spring boot project:
Application file :
@SpringBootApplication
@PropertySource("classpath:navi.properties") // <== injection here
@ImportResource({"classpath*:applicationContext.xml"}) // <== load the xml setting file
public class CApplication {
public static void main(String[] args) {
SpringApplication.run(CApplication.class, args);
}
}
As you can see, nothing fancy here... In my src/main/resources/navi.properties file :
USER_INFO_CLS=jp.co.xxx.yyy.fw.service.UserInfoService
in my applicationContext.xml
, I am trying to inject this value :
<bean id="userInfoService" class="${USER_INFO_CLS}"/>
But ./mvnw spring-boot:run
returns the error below :
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [${USER_INFO_CLS}] for bean with name 'userInfoService' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: ${USER_INFO_CLS}
I read many articles about it (like this one) and it sounds good....
Thanks
专注分享java语言的经验与见解,让所有开发者获益!
评论