0

私のDAOクラスにヒットできません。以下は私のアプリケーションファイルです

    @Controller
    public class HelloWorldController1 {
        @Autowired
        EmpServiceIntf empService;

        public EmpServiceIntf getEmpService() {
            return empService;
        }

         public myMethod(){
            List<Employee> empList = new ArrayList<Employee>();
            empList = empService.getAllemp(abc,pqr);
          }


    --------------------my interface class-----------------

    public interface EmpServiceIntf {
    List<Employee> getAllemp(String abc, String pqr);
    }

    -------------my implementation class----------------

    public class EmpServiceImpl implements EmpServiceIntf {
    private EmpServiceDAO empDAO = new EmpServiceDAO ();
        public List<Employee> getAllemp(String abc, String pqr) {
            return empDAO.getAllemp(abc, pqr);
        }
    }

------------------------applicationContext.xml------------------------
<?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:mvc="http://www.springframework.org/schema/mvc"   
    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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<!-- Activates various annotations to be detected in bean classes-->
<context:annotation-config />
<context:component-scan base-package="org.nea.rest.unsr" />
<context:component-scan base-package="org.nea.spring.services.implementations.Uniserv" />
<context:component-scan base-package="org.nea.spring.services.interfaces.uniservs" />


<bean id="uniservService"  class="org.nea.spring.services.implementations.Uniserv.UniservServiceJPAImpl" />


    <!--bean class="org.nea.rest.unsr.HelloWorldController1">
        <property name="uniservService" ref="uniservService"></property>
    </bean-->

<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
<mvc:annotation-driven />

</beans>
----------------------------------

今私の問題は; 上記の構成で myMethod() をヒットすると、EmpServiceImpl クラス メソッドに移動し、HelloWorldController1 クラスに戻ります。しかし、EmpServiceDAO メソッドにはヒットしませんでした。私の EmpServiceDAO getAllemp メソッド

4

1 に答える 1

1

これは、「Controller」から「DaoImpl」へのスケルトンの例です。

@Controller- コントローラー用 @Service- サービス @Repository用 - Dao用

@Controller
class YourController {
   @Autowire
   private YourService yourService;

   public String yourControllerMethod() {
       yourService.serviceMethod();
   }
}

interface YourService {
   void serviceMethod();
}

@Service
class YourServiceImpl implements YourService {
   @Autowire
   private YourDao yourDao;

   void serviceMethod(){
      yourDao.daoMethod();
   }
}

interface YourDao {
    void daoMethod();
}

@Repository
class YourDaoImpl implements YourDao {
    void daoMethod() {
    }
}

そしてあなたの「spring-mvc.xml」で <mvc:annotation-driven />

and 

<context:component-scan base-package="com.yourcompany.example" />

to drive @Controller, @Service and @Repository annotations.
于 2012-12-22T17:18:40.203 に答える