Hello

I'm trying to inject a datasource with the @Resource annotation:

@Repository
public class UserDao {

    @Resource(name = "SutkiDB")
    private DataSource SutkiDB;

     ...
}

When I try to deploy the application following trace is shown:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'SutkiDB' is defined
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:388)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:976)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:245)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
        at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:422)
        at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:497)
        at
org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:182)
        at
org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:104)
        at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:288)


Why? Isn't the datasource object found from the JNDI tree or what is the
problem?




The datasource is defined in the Global Context JNDI:

   jca:/console.dbpool/SutkiDB/JCAManagedConnectionFactory/SutkiDB

and in the ResourceAdapterModule (what is this by the way?) JNDI:

  console.dbpool/SutkiDB/1.0/rar



geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1";> 

        <environment>
        <moduleId>
                <groupId>fi.company.sutki</groupId>
                <artifactId>SutkiAdminGui</artifactId>
                <version>1.0</version>
                <type>car</type>
        </moduleId> 
        <dependencies>
                <dependency>
                <groupId>console.dbpool</groupId>
                    <artifactId>SutkiDB</artifactId>
            </dependency>
        </dependencies>                 
                <hidden-classes>
                        <filter>org.springframework</filter>
                        <filter>org.apache.commons.</filter>
                        <filter>org.apache.log4j</filter>
                </hidden-classes>    
                <inverse-classloading/>
        </environment>

        <context-root>/SutkiAdminTool</context-root>
        
        <!-- security settings, if any, goes here -->
        
        <resource-ref>
        <ref-name>jdbc/SutkiDB</ref-name>
        <resource-link>SutkiDB</resource-link>
    </resource-ref>
    
</web-app>

and in web.xml

        <resource-ref>
        <res-ref-name>jdbc/SutkiDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>


and spring's applicationContext.xml:

<?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:context="http://www.springframework.org/schema/context";
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
          
http://www.springframework.org/schema/context/spring-context-2.5.xsd";>
               
     <context:annotation-config/>
     <context:component-scan base-package="fi.company" />
     
</beans>




I'm using Apache Geronimo v2.1 and Spring 2.5.2.
Datasource connection was working fine with good old initialContext lookup:

    DataSource datasource = (DataSource)
initialContext.lookup("java:comp/env/jdbc/SutkiDB");




Regards
  Timo Ratilainen



-- 
View this message in context: 
http://www.nabble.com/Injecting-datasource-with-the-%40Resource-annotation-tp17647494s134p17647494.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

Reply via email to