2013-06-24 1 views
0

Это моя проблема: я начал тестировать AppFuse, чтобы понять, соответствует ли она моим потребностям или нет.AppFuse - Spring Hibernate - сеанс не найден для текущей темы

Итак, я начинаю создавать проект (AppFuse не Light, а не проект с несколькими модулями).

Затем я следовал за шагом из главы Persistance (используя Hibernate), создавая мои бобы, даос и управляющий.

Первая попытка: как предложено в руководстве, я просто настроил dao и manager, используя вспомогательные классы AppFuse (GenericDaoHibernate и GenericManager). Все работает нормально.

Вторая попытка: Мне нужно создать пользовательский Dao и пользовательский менеджер, чтобы иметь дело с моим конкретным бизнес-правил ... опять же после урока ... Теперь у меня есть эта проблема, которая делает меня с ума:

> 2013-06-24 
> 21:42:52.512:WARN:oejs.ServletHandler:/certificati/fornitore 
> org.hibernate.HibernateException: No Session found for current thread 
> at 
> org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) 
> at 
> org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:978) 
> at 
> org.appfuse.dao.hibernate.GenericDaoHibernate.getSession(GenericDaoHibernate.java:86) 
> at 
> org.appfuse.dao.hibernate.GenericDaoHibernate.getAll(GenericDaoHibernate.java:104) 
> at 
> org.appfuse.service.impl.GenericManagerImpl.getAll(GenericManagerImpl.java:71) 
> at 
> com.alessandrodonato.webapp.controller.FornitoreController.handleRequest(FornitoreController.java:57) 

Почему?

Я поставил все классы (контроллеры, даосские, бобы, менеджеров) в рамках того же пакета .webapp ( .webapp.controller * .webapp.dao * .webapp.dao.impl, ЕСС)

мой 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:tx="http://www.springframework.org/schema/tx" 
      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.xsd 
                http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx.xsd" 
      default-lazy-init="true"> 

     <!-- Activates scanning of @Autowired --> 
     <context:annotation-config/> 

     <!-- Activates scanning of @Repository and @Service --> 
     <context:component-scan base-package="com.alessandrodonato"/> 

     <!-- Add new DAOs here -->  <!-- <bean id="fornitoreDao" class="org.appfuse.dao.hibernate.GenericDaoHibernate"> 
      <constructor-arg value="com.alessandrodonato.webapp.model.Fornitore"/> 
     </bean> --> 

     <tx:annotation-driven/> 

     <!-- Add new Managers here -->  <bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> 
       <property name = "sessionFactory" ref = "sessionFactory" /> 
    </bean>  
    </beans> 

мой диспетчеру-servlet.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" 
     default-lazy-init="true"> 

    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
     <property name="exceptionMappings"> 
      <props> 
       <prop key="org.springframework.dao.DataAccessException"> 
        dataAccessFailure 
       </prop> 
      </props> 
     </property> 
    </bean> 

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
     <property name="maxUploadSize" value="2097152"/> 
    </bean> 

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="ApplicationResources"/> 
     <property name="useCodeAsDefaultMessage" value="true"/> 
    </bean> 

    <context:component-scan base-package="com.alessandrodonato.webapp"/> 

    <!-- Configures the @Controller programming model --> 
    <mvc:annotation-driven/> 

    <!-- Convenient way to map URLs to JSPs w/o having a Controller --> 
    <mvc:view-controller path="/admin/activeUsers" view-name="admin/activeUsers"/> 
    <mvc:view-controller path="/mainMenu" view-name="mainMenu"/> 

    <!-- View Resolver for JSPs --> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="requestContextAttribute" value="rc"/> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/WEB-INF/pages/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 

    <!-- Add additional controller beans here --> 

</beans> 

Моя головная боль растет ...

+0

Как выглядит ваш FornitoreController? Другими словами, как вы вводите GenericManager? –

+0

Привет, Мэтт, здесь мой контроллер https://code.google.com/p/certificati/source/browse/trunk/src/main/java/com/alessandrodonato/webapp/controller/FornitoreController.java – AlexD

+0

Если вы используете Autowired вместо этого Ресурса, это работает? –

ответ

0

Возможно, это было задано более года назад, но я надеюсь, что смогу помочь кому-то.

У меня была аналогичная проблема при запуске с использованием инфраструктуры appfuse. Оказывается, я продолжаю забывать добавлять один конструктор аргументов в свою реализацию пользовательского менеджера. Я думаю, что самая важная часть заключается в передаче autoired dao экземпляра до родительских классов.

Ожидаемого пример реализации пользовательских менеджеров:

@Service ("customManager")
общественного   класса   CustomManagerImpl   расширяет   GenericManagerImpl < пользователя,   Long >   реализует   CustomManager   {       частный   UserDao   userDao;
       
        @Autowired
        общественного   CustomManagerImpl (UserDao   userDao) {
                супер (и serDao);
                этот .userDao   =   userDao;
       }}

Надежда, что помогает.