2012-01-05 2 views
0

문제점이 있습니다. 모든 DAO를 및 서비스는 내가하지 여기 ApplicationContext.xml, DAO 및 Service가있는 Spring JPA는 NULL입니다.

<context:component-scan base-package="com.tipytut" /> 
<context:annotation-config /> 

<bean 
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 

<bean 
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 

<bean 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <value>/WEB-INF/classes/tipytut.properties</value> 
    </property> 
</bean> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${jdbc.driverClassName}" /> 
    <property name="url" value="${jdbc.url}" /> 
    <property name="username" value="${jdbc.username}" /> 
    <property name="password" value="${jdbc.password}" /> 
</bean> 

<bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
      <property name="database" value="MYSQL" /> 
      <property name="showSql" value="true" /> 
     </bean> 
    </property> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<tx:annotation-driven transaction-manager="transactionManager" /> 

applicationContext.xml

... 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext.xml 
    </param-value> 
</context-param> 
... 

와의 web.xml의 설정 부분입니다 :(것을 해결하는 방법을 수행 널 (null)입니다 나는이 같은 DAO 있습니다

@Repository("tagDAO") 
@Transactional 
public class TagDAOImpl extends JpaDAO implements TagDAO { 
    public List<Tag> getTags() { 
     return getList("SELECT t FROM Tag t"); 
    } 
} 

... 그리고 서비스를

내 컨트롤러에서 해당 서비스를 호출 할 때 16,
@Service("managementService") 
@Transactional 
public class ManagementServiceImpl implements ManagementService { 
    @Autowired 
    private TagDAO tagDAO; 

    public List<Tag> getTags() { 
     return tagDAO.getTags(); 
    } 
} 

, 그것은 어떤 도움을 이해할 수있을 것이다 항상

@Autowired 
private ManagementService managementService; 

public List<Tag> getTags() { 
    try { 
     managementService.getTags(); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
    return tags; 
} 

NULL입니다.

업데이트 : 내 프로젝트 HERE (매우 간단 함)을 업로드하여 누구나 볼 수 있습니다. 누군가가 그 점을 잘못 이해할 수 있기를 바랍니다. :

답변

1

내 질문을 업데이트하는 것을 잊어 버렸습니다. 마침내 알아 냈습니다! 내가 struts2-spring-plugin에 대한 종속성을 추가하는 것을 잊었다, 문제는 내가이 X- 대해이 나는 또한 정보를 추가 할 수

2

이 서비스/Dao가 com.tipytut 패키지에 있는지 확인하십시오. 컨텍스트 : annotation-config는 구성 요소 검사에서 자동으로 활성화됩니다. 컨트롤러에 @Controller 주석을 달거나 @Component를 통해 구성 요소를 만들었나요? Else it '이 감지되지 않을 것이다 당신이 수동으로 유선하지 않는 한 스프링 빈되지 않습니다.이 구성에서이

@Resource 
    private TagDAO tagDAO; 

으로 봄 콩

+1

한 사람이 저자가 대안을 할 수있는 ^^ 도움이 될 것입니다 (

희망 오류 메시지를 받았습니다 없다는 것입니다 XML의 명시 적 선언에 의해 –

+0

imo 서비스를 검색하고 DAO 패키지를 추가하면 작동합니다. – Fixus

+0

네, 그렇습니다. 도움을 주셔서 감사합니다. –

0

사용 @Resource 주석이 아닌 경우 그래서 Autowiring은 작동하지 않습니다 파일

컨트롤러에 @Controller으로 주석을 추가하고 @Resource 주석을 DAO와 같은 방식으로 서비스에 추가하십시오.

+0

도움을 주셔서 감사합니다. 그러나 작동하지 않습니다. –