[jboss-user] [Tomcat, HTTPD, Servlets & JSP] - @Resource dependency injection for Servlets - is implemented

Mikha do-not-reply at jboss.com
Mon Nov 12 16:49:36 EST 2007


Hi!

I'm having troubles trying to make @Resource dependency injection work for servlets. Here it is:

Servlet class, UserServlet.java:
=====================
    /** data source to use */
    @Resource(name="jdbc/TimeTrackerDS")
    private DataSource myDs;
=====================
    
web.xml:
======
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
		This servlet handler all non-admin UI
		<servlet-name>UserServlet</servlet-name>
		<servlet-class>
			com.vatamani.timetracker.webui.UserServlet
		</servlet-class>
		<init-param>
			<param-name>debug</param-name>
			<param-value>true</param-value>
		</init-param>
	

	<servlet-mapping>
		<servlet-name>UserServlet</servlet-name>
		<url-pattern>/user/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<jsp-config>
		<jsp-property-group>
			All JSP pages
			<url-pattern>/p/*</url-pattern>
			<include-prelude>/p/header.jspf</include-prelude>
			<include-coda>/p/footer.jspf</include-coda>
		</jsp-property-group>
	</jsp-config>
	<context-param>
		<param-name>
			javax.servlet.jsp.jstl.fmt.localizationContext
		</param-name>
		<param-value>
			com.vatamani.timetracker.webui.messages
		</param-value>
	</context-param>
</web-app>
======

jboss-web.xml:
==========
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jboss-web PUBLIC
    "-//JBoss//DTD Web Application 4.2//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
	<resource-ref>
		<res-ref-name>jdbc/TimeTrackerDS</res-ref-name>
		<jndi-name>TimeTrackerDS</jndi-name>
	</resource-ref>
</jboss-web>
==========

And during deployment, I got following exception, as if @Resource doesn't exist at all:
=========
 org.jboss.deployment.DeploymentException: resource-ref jdbc/TimeTrackerDS found in jboss-web.xml but not in web.xml
	at org.jboss.metadata.WebMetaData.importJBossWebXml(WebMetaData.java:1030)
	at org.jboss.metadata.WebMetaData.importXml(WebMetaData.java:770)
	at org.jboss.web.AbstractWebContainer.parseMetaData(AbstractWebContainer.java:763)
	... 87 more

When I tried to find out some JBoss - specific examples or documentation on using @Resource in servlets, I couldn't find any mention of it whatsoever. Is it implemented in 4.2.1 at all?

Any suggestions are welcome!

____________
WBW&R, Mikha


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103885#4103885

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103885



More information about the jboss-user mailing list