title: dao is always null in serviceimpl class
body: <p>Below is my code. I am using remoting to get reference to the service. once i get the service reference and try to get event.dao call i get a NPE in EventServiceImpl class. When I use xml based config it works but i want it to be annotation based.</p>
  
  <p>EventDao.class</p>
  
  <pre><code>public interface EventDao {
  
      void saveEvent(Event employee);
  
      List&lt;Event&gt; findAllEvents();
  
      void deleteEmployeeBySsn(String ssn);
  
      Event findBySsn(String ssn);
  
      void updateEvent(Event employee);
  }
  </code></pre>
  
  <p>EventImplDao.class</p>
  
  <pre><code>@Repository
  public class EventDaoImpl extends AbstractDao implements EventDao{
  
      public void saveEvent(Event employee) {
          persist(employee);
      }
  
      @SuppressWarnings("unchecked")
      public List&lt;Event&gt; findAllEvents() {
          Criteria criteria = getSession().createCriteria(Event.class);
          return (List&lt;Event&gt;) criteria.list();
      }
  </code></pre>
  
  <p>EventServiceImpl</p>
  
  <pre><code>@Service
  @Transactional
  public class EventServiceImpl implements EventService{
  
      private EventDao eventDao;
  
      public void setEventDao(EventDao eventDao) {
          this.eventDao = eventDao;
      }
  
      public void saveEvent(Event employee) {
          eventDao.saveEvent(employee);
      }
  
      public List&lt;Event&gt; findAllEvents() {
          return eventDao.findAllEvents();
      }
  </code></pre>
  
  <p>EventService</p>
  
  <pre><code>@ServiceInterface
  public interface EventService {
  
      void saveEvent(Event employee);
  
      List&lt;Event&gt; findAllEvents();
  
      void deleteEmployeeBySsn(String ssn);
  
      Event findBySsn(String ssn);
  
      void updateEvent(Event employee);
  }
  </code></pre>
  
  <p>appconfig</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = "com.xxx.spring")
  public class AppConfig {
  
      @Bean
      public com.xxx.spring.dao.EventDao EventDao() {
          return new EventDaoImpl();
      }
  
      @Bean
      public com.xxxx.spring.service.EventService eventService() {
          return new EventServiceImpl();
      }
  </code></pre>
  
  <p>hibernateconfig class</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan({ "com.xxxxx.configuration.hib" })
  public class HibernateConfiguration {
  
      @Bean
      public LocalSessionFactoryBean sessionFactory() {
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
          sessionFactory.setDataSource(dataSource());
          sessionFactory.setPackagesToScan(new String[] { "com.xxxxxx.spring.component" });
          sessionFactory.setHibernateProperties(hibProperties());
          return sessionFactory;
       }
  
      @Bean
      public DataSource dataSource() {
          FileUtils ft = new FileUtils();
          ft.getProperties();
          DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
          driverManagerDataSource.setDriverClassName(ft.getProperties().getProperty("driver"));
          driverManagerDataSource.setUrl(ft.getProperties().getProperty("url"));
          driverManagerDataSource.setUsername(ft.getProperties().getProperty("username"));
          driverManagerDataSource.setPassword(ft.getProperties().getProperty("password"));
          return driverManagerDataSource;
      }
      private Properties hibProperties() {
          Properties properties = new Properties();
          properties.put(Environment.DIALECT, "org.hibernate.dialect.SQLServer2012Dialect");
          properties.put(Environment.SHOW_SQL, false);
          return properties;
      }
  
      @Bean
      @Autowired
      public HibernateTransactionManager transactionManager(SessionFactory s) {
         HibernateTransactionManager txManager = new HibernateTransactionManager();
         txManager.setSessionFactory(s);
         return txManager;
      }
  }
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre class="lang-none prettyprint-override"><code>HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
  
  type Exception report
  
  message Request processing failed; nested exception is java.lang.NullPointerException
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  root cause
  
  java.lang.NullPointerException
      com.xxxx.spring.service.Impl.EventServiceImpl.findAllEvents(EventServiceImpl.java:28)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy24.findAllEvents(Unknown Source)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:78)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy25.findAllEvents(Unknown Source)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:212)
      org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:39)
      org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
      org.springframework.remoting.rmi.RmiBasedExporter.invoke(RmiBasedExporter.java:73)
      org.springframework.remoting.rmi.RmiInvocationWrapper.invoke(RmiInvocationWrapper.java:74)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
      sun.rmi.transport.Transport$1.run(Unknown Source)
      sun.rmi.transport.Transport$1.run(Unknown Source)
      java.security.AccessController.doPrivileged(Native Method)
      sun.rmi.transport.Transport.serviceCall(Unknown Source)
      sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
      sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
      sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(Unknown Source)
      java.security.AccessController.doPrivileged(Native Method)
      sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
      org.springframework.remoting.support.RemoteInvocationUtils.fillInClientStackTraceIfPossible(RemoteInvocationUtils.java:45)
      org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:353)
      org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:260)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy30.findAllEvents(Unknown Source)
      com.xxxx.controller.WebController.initiateEventsPage(WebController.java:35)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  note The full stack trace of the root cause is available in the Apache Tomcat/7.0.57 logs.
  </code></pre>
  
  <p>new error now. I think caused becaue eventDaoIml has <code>@Repository</code> attached to it. </p>
  
  <pre class="lang-none prettyprint-override"><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxxxx.spring.dao.EventDao com.xxx.spring.service.Impl.EventServiceImpl.eventDao; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.xxxi.spring.dao.EventDao] is defined: expected single matching bean but found 2: eventDaoImpl,EventDao
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
      ... 26 more
  Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [comxxx.i.spring.dao.EventDao] is defined: expected single matching bean but found 2: eventDaoImpl,EventDao
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:970)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
      ... 28 more
  </code></pre>