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:[email protected]] 
Sent: Thursday, May 17, 2012 5:38 PM
To: [email protected]
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, <[email protected]> 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:[email protected]]
> Sent: Thursday, May 17, 2012 5:34 PM
> To: [email protected]
> 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, <[email protected]>
> 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.UserService
> 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.

Reply via email to