I am integrating hibernate and spring and jsf.
I got this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sajjad.dao.UserDao com.sajjad.service.UserServiceImpl.userDao;
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.sajjad.dao.UserDao] is defined: expected single matching bean but found 2: orderDaoImpl,userDaoImpl.
Here is userServiceImpl:
@Service
public class UserServiceImpl implements UserService<User, Integer>, Serializable {
@Autowired
private UserDao userDao;
//other methods
And this is UserDaoImpl:
@Component
public class UserDaoImpl implements UserDao<User, Integer>, Serializable {
@Autowired
private SessionFactory sessionFactory;
// other methods
And here is applicationContext.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:c="http://ift.tt/MffYna"
xmlns:context="http://ift.tt/GArMu7"
xmlns:flow="http://ift.tt/19rsrif"
xmlns:jee="http://ift.tt/OpNaZ5"
xmlns:jms="http://ift.tt/1iMF6wC"
xmlns:lang="http://ift.tt/OGfeTY"
xmlns:osgi="http://ift.tt/1apCv6f"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:util="http://ift.tt/OGfeTW"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/18sW2ax
http://ift.tt/OpNdV1
http://ift.tt/JvbN5c
http://ift.tt/GArMu7
http://ift.tt/1bGeTcI
http://ift.tt/19rsrif
http://ift.tt/1iMF6wL
http://ift.tt/OpNaZ5
http://ift.tt/JvbN5h
http://ift.tt/1iMF6wC
http://ift.tt/1Fj1J6D
http://ift.tt/OGfeTY
http://ift.tt/1pFdnVn
http://ift.tt/1apCv6f
http://ift.tt/VRFjZG
http://ift.tt/OGfeU2
http://ift.tt/1cKeJ93
http://ift.tt/OGfeTW
http://ift.tt/1aj0W5e">
<!-- Activates scanning of @Autowired -->
<context:annotation-config/>
<!-- Activates scanning of @Repository and @Service -->
<context:component-scan base-package="com.sajjad.dao, com.sajjad.service, com.sajjad.user, com.sajjad.book"/>
<!-- Configure JDBC Connection-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/obs" />
<property name="username" value="root" />
<property name="password" value="2323" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:annotatedClasses="com.sajjad.model.Book, com.sajjad.model.User,
com.sajjad.model.Admin, com.sajjad.model.Order, com.sajjad.model.OrderItem "
p:packagesToScan="com.sajjad.dao"
p:hibernateProperties-ref="hibernateProperties"/>
<util:properties id="hibernateProperties">
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</util:properties>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Detect @Transactional Annotation -->
<tx:annotation-driven transaction-manager="transactionManager" />
Aucun commentaire:
Enregistrer un commentaire