Autowire JNDI Resource in Spring

狂风中的少年 提交于 2019-12-05 11:18:49

I use this configuration to inject a JNDI resource

spring config

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee.xsd">

    <jee:jndi-lookup id="destination" jndi-name="java:/queue/inbound/jndiname" />

</beans>

Class

@Autowired
private javax.jms.Destination destination;
Ivan Rodrigues
@Configuration
public class Configuration {
    @Bean(destroyMethod = "close")
    public DataSource dataSource() {
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(false);
        DataSource dataSource = dsLookup.getDataSource("my/service");       
        return dataSource;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!