2012-05-27 3 views
0

난 내가 하나 springapp-service.xml을 다음 봄과 최대 절전 모드 4를 구성하는 방법에 대해 3.1

<?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:jee="http://www.springframework.org/schema/jee" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd"> 

    <jee:jndi-lookup id="masterDS" jndi-name="java:jboss/datasources/MySqlDS" /> 
    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="masterDS" /> 
     <property name="hibernateProperties"> 
     <props> 
     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
     <prop key="hibernate.show_sql">true</prop> 
     </props> 
</property> 
    </bean> 
</beans> 

아래로는

<?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:aop="http://www.springframework.org/schema/aop" 
    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/tx 
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd "> 
    <bean id="txManager" 
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
     <property name="dataSource" ref="masterDS" /> 
    </bean> 
    <tx:advice id="txAdvice" transaction-manager="txManager"> 
    <tx:attributes> 
     <tx:method name="get*" read-only="true" propagation="REQUIRED"/> 
     <tx:method name="*" propagation="REQUIRED"/> 
    </tx:attributes> 
</tx:advice> 
    <aop:config> 
     <aop:pointcut expression="execution(* service.*.*(..))" 
      id="service" /> 
     <aop:advisor advice-ref="txAdvice" pointcut-ref="service" /> 
    </aop:config> 
    <bean id="contactDAO" class="dao.ContactDAOImpl"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 
    <bean id="contactService" class="service.ContactServiceImpl"> 
    <property name="contactDAO" ref="contactDAO"/> 
    </bean> 
</beans> 

을 따르처럼 보이는 한 springapp-dao.xml이 그리고 내가 한 DAOImpl

@Repository("ContactDAO") 
@Transactional(readOnly = false) 
public class ContactDAOImpl implements ContactDAO { 
private SessionFactory sessionFactory; 

    public SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 

    public void setSessionFactory(SessionFactory sessionFactory) { 
     this.sessionFactory = sessionFactory; 
    } 



public List<Contacts> listContact() { 

      return sessionFactory.openSession().createQuery("from Contacts") 
        .list(); 
     } 

} 

이 그럼이 제대로 연락처 테이블

0123에 매핑 한 POJO

@Entity 
@Table(name = "CONTACTS") 
public class Contacts { 

    @Id 
    @Column(name = "ID") 
    @GeneratedValue 
    // The @GeneratedValue annotation says that this value will be determined by 
    // the datasource, not by the code. 
    private Integer id; 

    @Column(name = "FIRSTNAME") 
    private String firstname; 

    @Column(name = "LASTNAME") 
    private String lastname; 

    @Column(name = "EMAIL") 
    private String email; 

    @Column(name = "TELEPHONE") 
    private String telephone; 
    @Column(name = "CREATED") 
    private String created; 
........

그럼 내가 하나 개의 서비스 클래스

@Service 
public class ContactServiceImpl implements ContactService { 


    private ContactDAO contactDAO; 

    public ContactDAO getContactDAO() { 
     return contactDAO; 
    } 

    public void setContactDAO(ContactDAO contactDAO) { 
     this.contactDAO = contactDAO; 
    } 

이 ...................

이제 질문이 두 개 있습니다. 먼저 ContactServiceImpl에서 ContactsDAOImpl 및 ContactDAO의 세션 공장을 autowire하려고 할 때 전혀 유선 상태가 아닙니다. 그런 다음 위에서 보았 듯이 setter 및 getters를 사용했습니다. 그런 다음 필요한 종속성을 주입하기 시작했습니다. 지금 내 문제는 내가의 listContact() ContactDAOImpl 방법, (내가 대신의 getConnection의 공장하지만 아무튼 작업에 열려있는 연결을 호출했다 첫째)입니다 때, 는 다음 던졌습니다입니다 exceptiopn

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Contacts is not mapped [from Contacts] 

내가해야합니까 당신은 당신이 당신의 클래스를 넣어 LocalSessionFactoryBean의 말할 필요 HBM의 FIL에게

답변

2

을 만드는, 그래서 어떤 패키지 연락처 클래스에합니다 :

<property name="packagesToScan" value="your.orm.package"/>