我有一个带有WildFly的Java EE应用程序,并且使用:
@Resource(lookup = "java:/jms/queue/MyQueue")
但是现在我正在将该应用程序的一部分迁移到Spring 1,并且我不知道如何查找我的JNDI资源。
在application.yaml
中,我添加了:
spring:
datasource:
jndi-name: "java:jms/queue/MyQueue"
但是在启动过程中会引发错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRoute': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'java:/jms/queue/MyQueue' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
MyRoute.java:
@Resource(lookup = "java:/jms/queue/MyQueue")
private Queue queue1;
是否可以在Spring中轻松注入资源?
我希望它能像@Autowired
一样工作。通过查询将队列注入JNDI。