2012-09-14 2 views
0

다음과 같은 beans.xml 및 persistence.xml 파일이있는 Wicket + Spring + JPA + Hibernate + MySQL 응용 프로그램이 있습니다.Wicket + Spring + JPA + Hibernate : 'dataSource'라는 Bean이 정의되지 않았습니다.

beans.xml 환경 나는 원시 SQL을 사용하기 위해 JdbcTemplate을을 사용하고자하는이 시점에서

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    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/tx 
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

    <!-- Scans for @Repository, @Service and @Component --> 
    <context:component-scan base-package="com.abc.app" /> 

    <!-- Enable @Transactional support --> 
    <tx:annotation-driven /> 

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

의 persistence.xml

<?xml version="1.0" encoding="UTF-8"?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
    version="1.0"> 
    <persistence-unit name="eppm" transaction-type="RESOURCE_LOCAL"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <properties> 
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />    
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost/eppm" /> 
      <property name="hibernate.connection.username" value="xxx" /> 
      <property name="hibernate.connection.password" value="xxx" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

. JdbcTemplate을 주입의 경우, 나는 배치시 내 beans.xml 환경

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 

    <bean id="textDao" class="com.fhlabs.dao.TestDaoService"> 
     <property name="jdbcTemplate" ref="jdbcTemplate"/> 
    </bean> 

에 다음을 포함 할 때, 모든 DB의 세부 사항을 지정하면 내가 여기에 명시 적으로는 dataSource의 세부 사항을 지정하려면 어떻게 오류

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTemplate' defined in class path resource [beans.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) 
... 

을 다음과 같이 끝 in persistence.xml 많은 감사합니다.

<context:property-placeholder location="classpath:spring.properties"/> 

그런 다음 데이터 소스를 선언의를 참조 : 당신이 그것을 정의 할 필요가 있으므로

+1

복제하십시오. – duffymo

답변

1

당신은 여기 ...,은 dataSource라는 빈을 참조하는 것은 예입니다, 먼저 내가 설정의 문서 파일을로드 구성 파일 설정 :

<!-- Declare a datasource that has pooling capabilities--> 
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
     destroy-method="close" 
     p:driverClass="${app.jdbc.driverClassName}" 
     p:jdbcUrl="${app.jdbc.url}" 
     p:user="${app.jdbc.username}" 
     p:password="${app.jdbc.password}" 
     p:acquireIncrement="5" 
     p:idleConnectionTestPeriod="60" 
     p:maxPoolSize="100" 
     p:maxStatements="50" 
     p:minPoolSize="10"/> 
+0

선언 할 때 dataSource sdia2000

+0

무슨 수업 얘기하고 있니? 드라이버 클래스에 따라 다르지만, 사용하는 데이터베이스에 따라 다르며 persistence.xml과 동일하게 사용하십시오. 오, 당신까지 데이터 소스 인터페이스를 구현하는 것은 무엇이든 ... – NimChimpsky

+0

다른 옵션은 org.apache.commons.dbcp.BasicDataSource, http://stackoverflow.com/questions/4190062/configure-spring-datasource-for-hibernate-and입니다. -transactional – NimChimpsky