2013-09-30 1 views
0

DAO impl 클래스에는 @repository annotation을 사용하고 beanRefContext.xml 구성에 정의 된 데이터 소스를 @autowire 또는 @resource 할 수 없습니다. JEE : JNDI 룩업 태그spring-config에서 @repository dao impl 클래스에 autowiring jee-jdni-lookup 데이터 소스 항목

나는 @Repository IMPL 클래스에 다음과 같은 시도

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName" 
    cache="true" resource-ref="true" lookup-on-startup="false" 
    proxy-interface="javax.sql.DataSource" /> 

주석 및 구성 요소 패키지 검사와 같은 장소에 필요한 모든 태그 항목을 가지고

@Resource(mappedName="jdbc/xyzName") 
private DataSource dataSource; 

@Resource(name="datasource") 
private DataSource dataSource; 

@Autowired 
private DataSource dataSource; 

도와주세요!

######### Main xml file ########## 
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 
    <!-- This will automatically declare several post-processors 
      including the AutowiredAnnotationBeanPostProcessor -->  
    <context:annotation-config/> 
    <context:component-scan base-package="com.domain"/> 
    <bean id="context" lazy-init="true" 
     class="org.springframework.context.support.ClassPathXmlApplicationContext"> 
     <constructor-arg value="ejbBeans.xml" /> 
    </bean>  
</beans> 

########## EJB beans xml file ################ 

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

    <tx:annotation-driven transaction-manager="someTransactionManager" /> 
    <bean 
     class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"> 
     <property name="alwaysUseJndiLookup" value="true" /> 
    </bean> 

    <bean id="someTransactionManager" 
     class="org.springframework.transaction.jta.WebSphereUowTransactionManager"> 
    </bean> 

    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName" 
     cache="true" resource-ref="true" lookup-on-startup="false" 
     proxy-interface="javax.sql.DataSource" /> 
</beans> 

지금 예외 java.lang.IllegalArgumentException가 아래 점점 '은 dataSource'또는 '의 JdbcTemplate을'아래 required..the되어

@Repository 공용 클래스 UtilityDAOImpl는 JdbcDaoSupport 구현을 확장 내 DAOImpl 클래스의 코드입니다 UtilityDAO { final String className = 유틸리티 DAOImpl.class.getName();

private JdbcTemplate jdbcTemplate ; 

@Autowired 
@Qualifier("dataSource") 
public void setJdbcTemplate(DataSource dataSource) { 
    this.jdbcTemplate = new JdbcTemplate(dataSource); 
} 

편집 : 내가

<bean id="context" lazy-init="true" 
    class="org.springframework.context.support.ClassPathXmlApplicationContext"> 
    <constructor-arg value="ejbBeans.xml" /> 
</bean> 

는 콩 FR를 가져올 수 있다는 것을 알고하지 않습니다이 예외

; nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required 
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required 
    at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:386) 
    at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:160) 
    at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:141) 
    at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:121) 
    at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:95) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
    at java.lang.reflect.Method.invoke(Method.java:600) 
    at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227) 
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:566) 
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:264) 
    at com.ibm.ejs.container.SessionBeanO.callPostConstructInterceptors(SessionBeanO.java:260) 
    at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:409) 
    at com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:45) 
    at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1031) 
    at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1141) 
    at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:84) 
    at com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:599) 
    at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3964) 
    at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3349) 
    at com..domain.ejb.facade.EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.processRequest(EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.java) 
    at com..domain.ejb.facade._EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.processRequest(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java) 
    at com..domain.ejb.facade._EJSRemote0SLRequestDelegatorFacad_35bfd46c_Tie._invoke(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java) 
    at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622) 
    at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475) 
    at com.ibm.rmi.iiop.ORB.process(ORB.java:513) 
    at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574) 
    at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841) 
    at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714) 
    at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63) 
    at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com.domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143) 
    at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:381) 
    ... 32 more 

그리고 질문

@Repository 
public class TempUtilityDAOImpl extends JdbcDaoSupport implements 
     TempUtilityDAO { 
    final String className = TempUtilityDAOImpl.class.getName(); 

    private JdbcTemplate jdbcTemplate ; 

    @Autowired 
    @Qualifier("dataSource") 
    public void setJdbcTemplate(DataSource dataSource) { 
     this.jdbcTemplate = new JdbcTemplate(dataSource); 
    } 

    private static String IS_DEALER_IN_Temp = "select count(id_dlr) from " 
      + TempConstants.DB_NAME_Temp + "V_Temp_DLR where id_dlr = ? with UR"; 


      /** 
    * Method verifies that Dealer is not an Canadian dealer. 
    * 
    * @param dealerID 
    * @return 
    * @throws TempSystemException 
    */ 
    public boolean verifyTempDealer(String dealerID) throws TempSystemException { 

     boolean isTempDealer = false; 
     final String methodName = "verifyTempDealer(String dealerID)"; 
     MSLog.debug(className, "Exiting Method : " + methodName); 
     int rowcount = getJdbcTemplate().queryForInt(IS_DEALER_IN_Temp, 
       dealerID); 

     if (rowcount > 0) { 
      isTempDealer = true; 
     } 

     MSLog.debug(className, "Exiting Method : " + methodName); 
     return isTempDealer; 
    } 
} 
+0

귀하의 전체 맥락을 알려주십시오. –

+0

의견을 주셔서 감사합니다. XML 설정 파일을 추가했습니다. 도움이 되길 바랍니다. –

+0

'EJB' XML 파일을 가져 오시겠습니까? 그 콩들이 당신의 다른 맥락에서 어떻게 끝나기를 기대합니까? –

답변

0

의 클래스를 얻었다 한 문맥에서 다른 문맥으로.

그런 다음 import 보내고 컨텍스트에서 사용할 수 ejbBeans.xml에 선언

<import resource="ejbBeans.xml"/> 

모든 콩을 사용해야합니다.

+0

나는 이것을 시도 할 것이지만 autowire와 resource를 사용하는 것이 맞습니까? 스프링 컨테이너가 jee : jndi-lookup 유형을 다른 봄 콩을 가져올 수있는 bean으로 취급합니까? –

+0

@ RK-Java 예. 'id '가있는 요소는 참조 가능한 bean입니다. 현재 상황에서만 존재해야합니다. –

+0

이제 예외가 발생합니다. java.lang.IllegalArgumentException : 'dataSource'또는 'jdbcTemplate'이 필요합니다.아래는 내 DAOImpl 클래스의 코드입니다 –

관련 문제