2014-10-07 5 views
5

주석을 사용하여 Spring 컨트롤러에서 JNDI 리소스를 autowire하는 방법을 알고 싶습니다.Spring의 Autowire JNDI 리소스

은 현재 내가

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
<property name="jndiName" value="my/service"/> 
</bean> 

어떤 방법이 있나요, 내가 주석을 사용하여 같은 일을 할 수있는 사용하여 리소스를 검색 할 수 있습니다? @Resource (name = "my/service")와 같은 것입니까?

+0

당신이 달성하기 위해 무엇을 찾고있는 불분명를 주입하는이 구성을 사용합니다. @Autowired를 사용하여 Spring 컨텍스트에서 모든 bean을 autowire 할 수있다. 식별자를 사용하고자한다면, 당신의 bean id는 그 목적을 수행한다. 그러나 JNDI factory bean을 autowire하려는 이유가 확실하지 않습니다. – Angad

+0

이 문제가 해결 되었습니까? 그렇다면 어떻게 해결 했습니까? – Xstian

답변

2

은 내가 JNDI 자원을

스프링 설정

<?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> 

클래스

@Autowired 
private javax.jms.Destination destination; 
+0

왜 코멘트없이 downvote? - .- ' – Xstian

6
@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; 
    } 
} 
관련 문제