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.UserServiceImpl">
>              <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.

Reply via email to