다음과 같은 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"/>
그런 다음 데이터 소스를 선언의를 참조 : 당신이 그것을 정의 할 필요가 있으므로
복제하십시오. – duffymo