cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <tom.waterho...@thomsonreuters.com>
Subject RE: @Inject annotation not working with Spring service
Date Mon, 21 May 2012 20:20:52 GMT
I figured out my issue.  

I have two bean definition files, one for a 'core' module and one for a 'web' module.  Both
do a component scan, but the web module's scan was not for the entire package:

Core - 
        <!-- Load all annotated beans from com.thomsonreuters -->
        <context:component-scan base-package="com.thomsonreuters"/>

Web - 
        <!-- Load all annotated beans from com.thomsonreuters -->
        <context:component-scan base-package="com.thomsonreuters.services"/>

Both bean definition files are loaded via the contextConfiguration param, so I expected that
both would take effect.  When I changed the Web file to load 'com.thomsonreuters' my injection
via annotations issue went away.

I'm not sure if this is expected behavior of a Spring container, I haven't done the research
at this point.  I did want to follow up with the group in case some pour sole ran into this
type of situation.

-----Original Message-----
From: Ted [mailto:r6squeegee@gmail.com] 
Sent: Thursday, May 17, 2012 5:44 PM
To: users@cxf.apache.org
Subject: Re: @Inject annotation not working with Spring service

not sure off hand, you'll have to make sure the component scan is loading that bean of yours
and it's matching either the name or the type properly.

This is a spring problem though not a CXF problem, in terms of CXF it should work as normal
as it's just a bean loaded by spring (I'm assuming the web service itself is loaded as a spring
bean in the same context).

You should just need to debug your spring contexts to find out what's up.


On Fri, May 18, 2012 at 10:40 AM, <tom.waterhouse@thomsonreuters.com> wrote:

> Componentscan:
>
> <?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"
>        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.1.xsd
>
> http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-3.1.xsd
>
> http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
>
>        <!-- Load all annotated beans from com.thomsonreuters -->
>        <context:component-scan base-package="com.thomsonreuters"/>
>
>        <!-- Process @PersistenceContext to inject entity manager 
> factory
> -->
>        <bean
> class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
> />
>         .
>        .
>        .
>
> -----Original Message-----
> From: Ted [mailto:r6squeegee@gmail.com]
> Sent: Thursday, May 17, 2012 5:38 PM
> To: users@cxf.apache.org
> Subject: Re: @Inject annotation not working with Spring service
>
> yeah but how have you put it in the spring context? i.e. componentscan?
> xml?  or???
>
> On Fri, May 18, 2012 at 10:36 AM, <tom.waterhouse@thomsonreuters.com>
> wrote:
>
> > I'm using the @Repository annotation for the DAO:
> >
> > @Repository("userDAO")
> > public class UserDAO {
> >        @PersistenceContext
> >        private EntityManager entityManager;
> >
> >        @Transactional
> >        public void persist(User user) {
> >                entityManager.persist(user);
> >        }
> >        .
> >        .
> >        .
> >
> >
> > -----Original Message-----
> > From: Ted [mailto:r6squeegee@gmail.com]
> > Sent: Thursday, May 17, 2012 5:34 PM
> > To: users@cxf.apache.org
> > Subject: Re: @Inject annotation not working with Spring service
> >
> > It shouldn't make any difference at all.
> >
> > I do the same thing but with the annotation @Component instead of 
> > @service and @autowired instead of @Inject.
> >
> > The only reason I can think of that it would be null is if you don't 
> > have a matching UserDao that's in the spring context... are you sure 
> > you have that object in the spring context?
> >
> >
> >
> > On Fri, May 18, 2012 at 10:22 AM, 
> > <tom.waterhouse@thomsonreuters.com>
> > wrote:
> >
> > > I have a service that I've created using the Spring @Service
> annotation.
> > >  I am injecting Spring dependencies into the service using the 
> > > @Inject annotation.  When I invoke my service I get a 
> > > NullPointerException when referencing the injected dependency (in 
> > > this
> case a DAO).
> > >
> > > @Service("userServiceImpl-2012-02-01")
> > > @WebService(serviceName = "UserService", name = "UserServicePort", 
> > > portName = "UserServicePort", targetNamespace = "
> > > http://www.thomsonreuters.com/services/userservice/2012-02-01")
> > > public class UserServiceImpl implements UserService {
> > >
> > >       @Inject
> > >       private UserDAO userDAO;
> > >
> > >       public UserCollectionResponse findUserByName(String userName) {
> > >              Collection<com.thomsonreuters.persistence.User>
> > > userEntityCollection = userDAO.findByName(userName);
> > >
> > >              UserCollectionResponse userCollectionResponse = new 
> > > UserCollectionResponse();
> > >              userCollectionResponse.userCollection = 
> > > userConverter.convertToServiceObject(userEntityCollection);
> > >
> > >              return userCollectionResponse;
> > >       }
> > > }
> > >
> > > When I do the same via bean definition files, so services defined 
> > > as bean in file and dependencies injected via the bean definition 
> > > in the file, all works okay.
> > >
> > >       <bean id="userServiceImpl-2012-02-01"
> > >
> > class="com.thomsonreuters.services.userservice._2012_02_01.UserServi
> > ce
> > Impl">
> > >              <property name="userDAO" ref="userDAO"/>
> > >              <property name="userConverter" ref="userConverter"/>
> > >       </bean
> > >
> > >      <jaxws:endpoint id="userServiceEndPoint-2012-02-01"
> > >
> >  implementor="#userServiceImpl-2012-02-01"
> > >
> > >  address="/userservice/2012-02-01/userservice"
> > > wsdlLocation="UserService.wsdl">
> > >              <jaxws:properties>
> > >                     <entry key="schema-validation-enabled"
> value="true"/>
> > >              </jaxws:properties>
> > >       </jaxws:endpoint>
> > >
> > > Anyone run into something like this?  I'm not sure how using the 
> > > annotations instead of the file definitions would cause any issues.
> > > Tom
> > >
> > >
> >
> >
> > --
> > Ted.
> >
>
>
>
> --
> Ted.
>



--
Ted.

Mime
View raw message