JNDI @Resource在春季

时间:2020-10-01 13:52:36

标签: java spring jndi

我有一个带有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。

0 个答案:

没有答案