geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gianny Damour <gianny.dam...@optusnet.com.au>
Subject Re: Injecting datasource with the @Resource annotation
Date Wed, 04 Jun 2008 21:48:50 GMT
Hello Timo,

This @Resource annotation will be processed and resolved by Spring 2.5 
+. You need to define a bean named SutkiDB in your Spring application  
context by using the standard Spring provided JNDI lookup helpers.

FWIW, I believe that the @Autowired annotation is way more flexible  
and powerful than the @Resource one. So, you may want to use  
@Autowired instead.

Thanks,
Gianny

On 05/06/2008, at 12:01 AM, timo.ratilainen wrote:

>
> 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.g 
> etBeanDefinition(DefaultListableBeanFactory.java:388)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getMerge 
> dLocalBeanDefinition(AbstractBeanFactory.java:976)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBea 
> n(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.CommonAnnotationBeanPostProcess 
> or.getResource(CommonAnnotationBeanPostProcessor.java:422)
>         at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcess 
> or$ResourceElement.getResourceToInject 
> (CommonAnnotationBeanPostProcessor.java:497)
>         at
> org.springframework.beans.factory.annotation.InjectionMetadata 
> $InjectedElement.inject(InjectionMetadata.java:182)
>         at
> org.springframework.beans.factory.annotation.InjectionMetadata.injectF 
> ields(InjectionMetadata.java:104)
>         at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcess 
> or.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.
>


Mime
View raw message