You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by vpyang <vp...@hotmail.com> on 2016/03/11 17:06:39 UTC

@autowired object null

Hello,

I'm looking to deploy a RESTful web service using TomEE with spring 3.0.6
but I"m running into a road block.  I've got my service up and running but
when I try to access it I get a null pointer.  It seems my @autowired object
is null.  I'm pretty new with these server setup so any help is much
appreciated!  Thanks!



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: @autowired object null

Posted by Romain Manni-Bucau <rm...@gmail.com>.
you can need to add few jars but the base is there
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Spring


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-03-11 18:03 GMT+01:00 vpyang <vp...@hotmail.com>:

> I don't want to use Jersey, so do how would I do the CXF spring
> integration?
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863p4677867.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: @autowired object null

Posted by vpyang <vp...@hotmail.com>.
I don't want to use Jersey, so do how would I do the CXF spring integration?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863p4677867.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: @autowired object null

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-03-11 17:24 GMT+01:00 vpyang <vp...@hotmail.com>:

> Thank you for the quick reply.
>
> here is my web.xml:
>
> <context-param>
>                 <param-name>contextConfigLocation</param-name>
>                 <param-value>
>                         classpath:applicationContext.xml
>                 </param-value>
>         </context-param>
>
>         <resource-ref>
>                 <description>TransWSDs</description>
>                 <res-ref-name>trans-ws/TransWSDS</res-ref-name>
>                 <res-type>javax.sql.DataSource</res-type>
>                 <res-auth>Container</res-auth>
>         </resource-ref>
>
>         <listener>
>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>         </listener>
>
>         <context-param>
>                 <param-name>log4jConfigLocation</param-name>
>                 <param-value>classpath:log4j.properties</param-value>
>     </context-param>
>
>     <listener>
>
>
> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
>     </listener>
>
> the resource.xml:
> <Resource id="TransWSDS" type="javax.sql.DataSource">
>                 XaDataSource TransWSXDS
>                 DataSourceCreator dbcp
>                 UserName test
>                 Password xxxx
>                 ValidationQuery SELECT SYSDATE FROM DUAL
>         </Resource>
>         <Resource id="TransWSXDS" type="XADataSource"
> class-name="oracle.jdbc.xa.client.OracleXADataSource">
>                 Url     jdbc:oracle:thin:@(DESCRIPTION =
> (CONNECT_TIMEOUT=10) (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521)))
> (CONNECT_DATA
> = (SERVER = DEDICATED) (SERVICE_NAME = test)))
>                 User test
>                 Password xxxx
>         </Resource>
>
> applicationContext.xml:
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:p="http://www.springframework.org/schema/p"
>         xmlns:context="http://www.springframework.org/schema/context"
> xmlns:util="http://www.springframework.org/schema/util"
>         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/util
> http://www.springframework.org/schema/util/spring-util-3.0.xsd">
>
>         <context:annotation-config />
>         <context:component-scan base-package="net.test.adm.na"/>
>         <context:component-scan base-package="net.test.adm.ms"/>
>
>         <import resource="classpath*:transLibContext.xml"/>
>
>         <bean id="propertyPlaceholderConfigurer"
>
>
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>                 lazy-init="false">
>                 <property name="systemPropertiesMode">
>
>                         <util:constant
>
>
> static-field="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE"
> />
>                 </property>
>                 <property name="locations">
>                         <list>
>
> <value>classpath*:/application.properties</value>
>                         </list>
>                 </property>
>         </bean>
>
>         <bean id="perfLoggerFactory"
> class="net.tds.adm.na.commons.perf.PerfLoggerFactory"/>
>         <bean id="perfLogger"
> class="net.tds.adm.na.commons.perf.PerfLogger"
>                 factory-bean="perfLoggerFactory"
> factory-method="newPerfLogger"/>
>
> </beans>
>
> and the transLibContext.xml:
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:p="http://www.springframework.org/schema/p"
>        xmlns:context="http://www.springframework.org/schema/context"
>        xmlns:task="http://www.springframework.org/schema/task"
>        xmlns:tx="http://www.springframework.org/schema/tx"
>        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/task
> http://www.springframework.org/schema/task/spring-task-3.0.xsd
>         http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx.xsd">
>
>         <context:component-scan base-package="net.test.adm.ms"/>
>
>         <bean id="transConvDataSource"
>               class="org.springframework.jndi.JndiObjectFactoryBean">
>                 <property name="jndiName"
> value="java:comp/env/trans-ws/TransWSDS"/>
>         </bean>
>
>         <bean id="transConvTransactionManager"
>
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>                 <property name="dataSource"
>                           ref="transConvDataSource"/>
>         </bean>
>
>         <tx:annotation-driven
> transaction-manager="backhaulTransactionManager" />
>
>         <bean id="transConvJdbcTemplate"
>               class="org.springframework.jdbc.core.JdbcTemplate">
>                 <constructor-arg index="0"
>                                  type="javax.sql.DataSource"
>                                  ref="transConvDataSource"/>
>         </bean>
>
>         <bean id="transConvNamedParameterJdbcTemplate"
>
>
> class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
>                 <constructor-arg index="0"
>
>  type="org.springframework.jdbc.core.JdbcOperations"
>                                  ref="transConvJdbcTemplate"/>
>         </bean>
> </beans>
>
> As for CDI and @Injection as well as deploy spring and jaxrs do you have
> any
> docs/examples I could look at?
>
>
For CDI https://github.com/apache/tomee/blob/master/examples/rest-cdi/ and
in particular its src/main/java/org/superbiz/rest/GreetingService.java is a
good example. If you still want to stick with JAXRS you can need to import
jersey or CXF spring integration but if you don't have to stick to spring
using CDI can make this smoother in this case.


>
> Romain Manni-Bucau wrote
> > Hi
> >
> > what's your setup? Any sample reproducing the issue with
> > tomee-maven-plugin
> > on github?
> >
> > Side note: not sure your context but tomee doesn't instantiate spring
> > instances so if the JAXRS service is deployed by tomee it ignored
> > @Autowired.
> *
> > You can use CDI and @Inject to get it running without spring
> > out of the box or you need to deploy spring and JAXRS services yourself.
> *
> >
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <http://rmannibucau.wordpress.com> | Github
> > <https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com>
> >
> > 2016-03-11 17:06 GMT+01:00 vpyang <
>
> > vpyang@
>
> > >:
> >
> >> Hello,
> >>
> >> I'm looking to deploy a RESTful web service using TomEE with spring
> 3.0.6
> >> but I"m running into a road block.  I've got my service up and running
> >> but
> >> when I try to access it I get a null pointer.  It seems my @autowired
> >> object
> >> is null.  I'm pretty new with these server setup so any help is much
> >> appreciated!  Thanks!
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863.html
> >> Sent from the TomEE Users mailing list archive at Nabble.com.
> >>
>
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863p4677865.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: @autowired object null

Posted by vpyang <vp...@hotmail.com>.
Thank you for the quick reply.

here is my web.xml:

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:applicationContext.xml
		</param-value>
	</context-param>
	
	<resource-ref>
		<description>TransWSDs</description>
		<res-ref-name>trans-ws/TransWSDS</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>
	
	<listener>
	
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:log4j.properties</param-value>
    </context-param>

    <listener>
	
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

the resource.xml:
<Resource id="TransWSDS" type="javax.sql.DataSource">
		XaDataSource TransWSXDS
		DataSourceCreator dbcp
		UserName test
		Password xxxx
		ValidationQuery	SELECT SYSDATE FROM DUAL
	</Resource>
	<Resource id="TransWSXDS" type="XADataSource"
class-name="oracle.jdbc.xa.client.OracleXADataSource">
		Url	jdbc:oracle:thin:@(DESCRIPTION = (CONNECT_TIMEOUT=10) (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521))) (CONNECT_DATA
= (SERVER = DEDICATED) (SERVICE_NAME = test)))
		User test
		Password xxxx
	</Resource>

applicationContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
	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/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">

	<context:annotation-config />
	<context:component-scan base-package="net.test.adm.na"/>
	<context:component-scan base-package="net.test.adm.ms"/>

	<import resource="classpath*:transLibContext.xml"/>
	
	<bean id="propertyPlaceholderConfigurer"
	
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
		lazy-init="false">
		<property name="systemPropertiesMode">
			
			<util:constant
			
static-field="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE"
/>
		</property>
		<property name="locations">
			<list>
				<value>classpath*:/application.properties</value>
			</list>
		</property>
	</bean>
	
	<bean id="perfLoggerFactory"
class="net.tds.adm.na.commons.perf.PerfLoggerFactory"/>
	<bean id="perfLogger" class="net.tds.adm.na.commons.perf.PerfLogger"
		factory-bean="perfLoggerFactory" factory-method="newPerfLogger"/>
	
</beans>

and the transLibContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
	http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

	<context:component-scan base-package="net.test.adm.ms"/>
	
	<bean id="transConvDataSource"
	      class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="java:comp/env/trans-ws/TransWSDS"/>
	</bean>
	
	<bean id="transConvTransactionManager"
	     
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource"
		          ref="transConvDataSource"/>
	</bean>

	<tx:annotation-driven transaction-manager="backhaulTransactionManager" />

	<bean id="transConvJdbcTemplate"
	      class="org.springframework.jdbc.core.JdbcTemplate">
		<constructor-arg index="0"
		                 type="javax.sql.DataSource"
		                 ref="transConvDataSource"/>
	</bean>

	<bean id="transConvNamedParameterJdbcTemplate"
	     
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
		<constructor-arg index="0"
		                 type="org.springframework.jdbc.core.JdbcOperations"
		                 ref="transConvJdbcTemplate"/>
	</bean>
</beans>

As for CDI and @Injection as well as deploy spring and jaxrs do you have any
docs/examples I could look at?


Romain Manni-Bucau wrote
> Hi
> 
> what's your setup? Any sample reproducing the issue with
> tomee-maven-plugin
> on github?
> 
> Side note: not sure your context but tomee doesn't instantiate spring
> instances so if the JAXRS service is deployed by tomee it ignored
> @Autowired. 
*
> You can use CDI and @Inject to get it running without spring
> out of the box or you need to deploy spring and JAXRS services yourself.
*
> 
> 
> 
> Romain Manni-Bucau
> @rmannibucau &lt;https://twitter.com/rmannibucau&gt; |  Blog
> &lt;http://rmannibucau.wordpress.com&gt; | Github
> &lt;https://github.com/rmannibucau&gt; |
> LinkedIn &lt;https://www.linkedin.com/in/rmannibucau&gt; | Tomitriber
> &lt;http://www.tomitribe.com&gt;
> 
> 2016-03-11 17:06 GMT+01:00 vpyang &lt;

> vpyang@

> &gt;:
> 
>> Hello,
>>
>> I'm looking to deploy a RESTful web service using TomEE with spring 3.0.6
>> but I"m running into a road block.  I've got my service up and running
>> but
>> when I try to access it I get a null pointer.  It seems my @autowired
>> object
>> is null.  I'm pretty new with these server setup so any help is much
>> appreciated!  Thanks!
>>
>>
>>
>> --
>> View this message in context:
>> http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863.html
>> Sent from the TomEE Users mailing list archive at Nabble.com.
>>





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863p4677865.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: @autowired object null

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

what's your setup? Any sample reproducing the issue with tomee-maven-plugin
on github?

Side note: not sure your context but tomee doesn't instantiate spring
instances so if the JAXRS service is deployed by tomee it ignored
@Autowired. You can use CDI and @Inject to get it running without spring
out of the box or you need to deploy spring and JAXRS services yourself.



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-03-11 17:06 GMT+01:00 vpyang <vp...@hotmail.com>:

> Hello,
>
> I'm looking to deploy a RESTful web service using TomEE with spring 3.0.6
> but I"m running into a road block.  I've got my service up and running but
> when I try to access it I get a null pointer.  It seems my @autowired
> object
> is null.  I'm pretty new with these server setup so any help is much
> appreciated!  Thanks!
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/autowired-object-null-tp4677863.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>