|
From: Cecil N. <cec...@gm...> - 2008-05-02 20:09:53
|
Hello- A question on resteasy and spring...
I have used resteasy to connect to my database as a test case by hard/soft
coding in a properties file. But to do it right I am trying to switch to a
connection pool. So I put together the applicationContext.xml file for
Spring, etc. It isn't working yet... I have tried various approaches, but
bottom line, it looks like spring is creating instances and so is resteasy.
So when resteasy tries to get my jdbc template instance, it is always null.
Based on the wiki article on this subject, I think the resteasy spring
version is supposed to inject *after* resteasy creates the instance. I
suspect there's more config info that I am missing. Hope someone can point
the way here.
Thanks
Here are some snippets in case it helps:
*from web.xml*
<web-app>
<!-- JSR 311 stuff -->
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.resteasy.plugins.server.servlet.SpringContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
</web-app>
*from applicationContext.xml*
<bean id="plmwh"
class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="true">
<property name="jndiName" value="plmwh"></property>
</bean>
<bean id="gxoJdbcTemplate" class="gxo.dao.GXOJDBCTemplate">
<constructor-arg value="true" />
<property name="dataSource" ref="plmwh" />
</bean>
<bean id="dbquery3_dao" class="dbquery3_dao" >
<property name="jdbcTemplate">
<ref bean="gxoJdbcTemplate" />
</property>
</bean>
|
|
From: Bill B. <bb...@re...> - 2008-05-02 20:19:01
|
Cecil New wrote: > Hello- A question on resteasy and spring... Are the beans being instantiated by Spring ok, but the request isn't being dispatched to the beans created by Spring? I think you need turn off scanning, or just remove these lines > <!-- JSR 311 stuff --> > <display-name>Archetype Created Web Application</display-name> > <context-param> > <param-name>resteasy.scan</param-name> > <param-value>true</param-value> > </context-param> > Turn off scanning by setting resteasy.scan to false. I think removing that context-param declaration will work too. Let me know how it goes. Bill -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Cecil N. <cec...@gm...> - 2008-05-02 20:57:29
|
If I turn of scanning or remove context-param, I get a 404 > Are the beans being instantiated by Spring ok, but the request isn't being > dispatched to the beans created by Spring? > So I think the later is the case. Here is console output. Notice that no JAX-RX resources are registered. The STDOUT lines show the bean actions at work. The DAO var isn't null at that point. Both variations are below. Thanks for your help. *Console output without the scan (results in 404):* 16:45:04,544 INFO [[/restdb3]] Initializing Spring root WebApplicationContext 16:45:04,544 INFO [ContextLoader] Root WebApplicationContext: initialization st arted 16:45:04,575 INFO [XmlWebApplicationContext] Refreshing org.springframework.web .context.support.XmlWebApplicationContext@ab6a53: display name [Root WebApplicat ionContext]; startup date [Fri May 02 16:45:04 EDT 2008]; root of context hierar chy 16:45:04,638 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from S ervletContext resource [/WEB-INF/applicationContext.xml] 16:45:04,716 INFO [XmlWebApplicationContext] Bean factory for application conte xt [org.springframework.web.context.support.XmlWebApplicationContext@ab6a53]: or g.springframework.beans.factory.support.DefaultListableBeanFactory@11e4bcc 16:45:05,606 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@11e4bcc: de fining beans [plmwh,geJdbcTemplate,dbquery3_dao,getpart]; root of factory hierar chy 16:45:05,700 INFO [STDOUT] == JDBC Template is set == 16:45:05,700 INFO [STDOUT] is not null! 16:45:05,700 INFO [STDOUT] ==> DAO set; is null? false 16:45:05,700 INFO [ContextLoader] Root WebApplicationContext: initialization co mpleted in 1156 ms *Console output when scan is on: * 16:51:21,511 INFO [TomcatDeployer] deploy, ctxPath=/restdb3, warUrl=.../tmp/dep loy/tmp9697restdb3-exp.war/ 16:51:22,745 INFO [STDOUT] FOUND JAX-RS resource: dbquery3 16:51:22,792 INFO [[/restdb3]] Initializing Spring root WebApplicationContext 16:51:22,792 INFO [ContextLoader] Root WebApplicationContext: initialization st arted 16:51:22,823 INFO [XmlWebApplicationContext] Refreshing org.springframework.web .context.support.XmlWebApplicationContext@1e27ea6: display name [Root WebApplica tionContext]; startup date [Fri May 02 16:51:22 EDT 2008]; root of context hiera rchy 16:51:22,901 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from S ervletContext resource [/WEB-INF/applicationContext.xml] 16:51:22,964 INFO [XmlWebApplicationContext] Bean factory for application conte xt [org.springframework.web.context.support.XmlWebApplicationContext@1e27ea6]: o rg.springframework.beans.factory.support.DefaultListableBeanFactory@17455a9 16:51:22,995 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17455a9: de fining beans [plmwh,geJdbcTemplate,dbquery3_dao,getpart]; root of factory hierar chy 16:51:23,073 INFO [STDOUT] == JDBC Template is set == 16:51:23,089 INFO [STDOUT] is not null! 16:51:23,089 INFO [STDOUT] ==> DAO set; is null? false 16:51:23,089 INFO [ContextLoader] Root WebApplicationContext: initialization co mpleted in 297 ms 16:51:53,166 INFO [STDOUT] DAO is null |
|
From: Bill B. <bb...@re...> - 2008-05-02 21:18:40
|
I'm baffled. Here's a simple I used to test things: http://resteasy.svn.sourceforge.net/viewvc/resteasy/trunk/jaxrs/jboss-integration-testing/spring-integration-test/ One thing I noted in your previous email. Are you sure you have the correct class name in your bean definition? <bean id="dbquery3_dao" class="dbquery3_dao" > <property name="jdbcTemplate"> <ref bean="gxoJdbcTemplate" /> </property> </bean> the id is the same as the "class" attribute. Is this a typo? cut/paste error? -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Cecil N. <cec...@gm...> - 2008-05-03 03:41:17
|
On Fri, May 2, 2008 at 5:20 PM, Bill Burke <bb...@re...> wrote: > I'm baffled. Here's a simple I used to test things: > > > http://resteasy.svn.sourceforge.net/viewvc/resteasy/trunk/jaxrs/jboss-integration-testing/spring-integration-test/ > Took your example and modified it a bit to do some bean wiring. The first thing I noticed is that you use spring 2.5... I'm still at 2.0. Do you know if that is a strict dependency? Assuming not... Not sure that the mail list can take attachments, but I'll try that first. - tweaked the LocatingResource.java code to add some get/set methods for spring to use when configuring the bean. - Added setup in applicationContext.xml and reverted to spring 2.0 - Set the scan to true (otherwise no jax-rs classes get registered - Tweaked my standard build.xml to handle the directories in this case Here is console output on deploy and a few lines after a test url. You will see that on startup the new variable in LocatingResouce is set to "OK" by spring. But on the GET url, it is null. {Hoping that maybe this is all due to need for spring 2.5 and that it isn't something more serious. I'll take a stab using 2.5 next with this revised example.} Thanks for your help. 23:27:31,665 INFO [TomcatDeployer] deploy, ctxPath=/spring-integration-test, wa rUrl=.../tmp/deploy/tmp61989spring-integration-test-exp.war/ 23:27:32,587 INFO [STDOUT] FOUND JAX-RS resource: org.jboss.resteasy.test.smoke .LocatingResource 23:27:32,618 INFO [STDOUT] FOUND JAX-RS resource: org.jboss.resteasy.test.smoke .SimpleResource 23:27:32,633 INFO [[/spring-integration-test]] Initializing Spring root WebAppl icationContext 23:27:32,633 INFO [ContextLoader] Root WebApplicationContext: initialization st arted 23:27:32,665 INFO [XmlWebApplicationContext] Refreshing org.springframework.web .context.support.XmlWebApplicationContext@abe449: display name [Root WebApplicat ionContext]; startup date [Fri May 02 23:27:32 EDT 2008]; root of context hierar chy 23:27:32,743 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from S ervletContext resource [/WEB-INF/applicationContext.xml] 23:27:32,805 INFO [XmlWebApplicationContext] Bean factory for application conte xt [org.springframework.web.context.support.XmlWebApplicationContext@abe449]: or g.springframework.beans.factory.support.DefaultListableBeanFactory@11f81b0 23:27:32,837 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@11f81b0: de fining beans [simple,locating]; root of factory hierarchy 23:27:32,868 INFO [STDOUT] Inside setSpringTest() with OK 23:27:32,868 INFO [ContextLoader] Root WebApplicationContext: initialization co mpleted in 235 ms http://localhost/spring-integration-test/locating/basic 23:28:10,712 INFO [STDOUT] LOCATING...(null) 23:28:10,712 INFO [STDOUT] getBasic() |
|
From: Cecil N. <cec...@gm...> - 2008-05-03 04:09:30
|
Yup... spring 2.5 did the trick. I'll start on my database pilot app now and use 2.5 there too. Here's hoping! Thanks! 00:06:41,468 INFO [STDOUT] Inside setSpringTest() with OK 00:06:41,468 INFO [ContextLoader] Root WebApplicationContext: initialization co mpleted in 250 ms 00:07:19,577 INFO [STDOUT] LOCATING...(OK) 00:07:19,593 INFO [STDOUT] getBasic() |
|
From: Bill B. <bb...@re...> - 2008-05-03 05:07:33
|
I'll check the Spring api difference between 2.0 and 2.5. Cecil New wrote: > Yup... spring 2.5 did the trick. I'll start on my database pilot app > now and use 2.5 there too. Here's hoping! > > Thanks! > > > 00:06:41,468 INFO [STDOUT] Inside setSpringTest() with OK > 00:06:41,468 INFO [ContextLoader] Root WebApplicationContext: > initialization co > mpleted in 250 ms > 00:07:19,577 INFO [STDOUT] LOCATING...(OK) > 00:07:19,593 INFO [STDOUT] getBasic() -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |