IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

[Spring][JPA][Hibernate] NoSuchBeanDefinitionException: No qualifying bean of type [hibernate.SessionFactory] [Data]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de amadoulamine1
    Inscrit en
    Avril 2005
    Messages
    260
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 260
    Par défaut [Spring][JPA][Hibernate] NoSuchBeanDefinitionException: No qualifying bean of type [hibernate.SessionFactory]
    Bonjour à tous
    J'ai décidé de migrer vers JPA pour avoir accès aux fonctionnalités @PreUpdated @PreCreated

    Je mets les paramètres mais je me retrouve avec une erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sfdDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    Je vous affiche les parametres :

    persistence.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <?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="generic-dao" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
       	    <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.show_sql" value="true" />
    		<property name="hibernate.format_sql" value="true" />
    		<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    		<property name="hibernate.hbm2ddl.auto" value="none" />
    		<property name="hibernate.connection.driver_class" value="${jdbc.driverClassName}"/>
                <property name="hibernate.connection.url" value="${jdbc.url}"/>
                <property name="hibernate.connection.username" value="${jdbc.username}"/>
                <property name="hibernate.connection.password" value="${jdbc.password}"/>
                <property name="hibernate.show_sql" value="true"/>
                <property name="hibernate.format_sql" value="true"/>
                <property name="hibernate.use_sql_comments" value="false"/>
                <property name="hibernate.query.substitutions" value="true 1, false 0"/>
        </properties>
      </persistence-unit>
     
    </persistence>
    applicationContext-dao.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <?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:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd" default-lazy-init="true">
     
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="generic-dao" />
    		<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
    		<property name="dataSource" ref="dataSource" />
    		<property name="loadTimeWeaver">
    			<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    		</property>
    		<property name="jpaVendorAdapter" ref="vendorAdapter" />
    	</bean>
     
    	<bean id="vendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    		<property name="databasePlatform" value="${hibernate.dialect}" />
    		<property name="showSql" value="true" />
    		<property name="generateDdl" value="false" />
    	</bean>
     
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
     
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    	<tx:annotation-driven />
     
    	<bean id="searchProcessor" class="com.googlecode.genericdao.search.jpa.JPASearchProcessor">
    		<constructor-arg ref="metadataUtil" />
    	</bean>
     
    	<bean id="metadataUtil" class="com.googlecode.genericdao.search.jpa.hibernate.HibernateMetadataUtil"
    		factory-method="getInstanceForEntityManagerFactory">
    		<constructor-arg ref="entityManagerFactory" />
    	</bean>
     
        <!-- Activates scanning of @Autowired -->
         <context:annotation-config/>
     
        <!-- Activates scanning of @Repository -->
        <context:component-scan base-package="com.dao.sem"/>
        <context:component-scan base-package="com.service.sem" />
     
    </beans>
    applicationContext-ressources.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?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-4.2.xsd
                http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
     
         <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location">
                <value>classpath:jdbc.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 class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    </beans>
    applicationContext.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?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:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
    	default-lazy-init="true">
     
    	<!-- Activates scanning of @Autowired -->
    	<context:annotation-config />
     
    	<!-- Activates scanning of @Repository and @Service -->
    	<context:component-scan base-package="com.web.sem" />
    </beans>
    SfdDao.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    @Transactional
    @Repository("sfdDao")
    public class SfdDao extends GenericDao<Sfd, Serializable> implements ISfdDao{
     
    }
    GenericDao.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    @Repository
    @Transactional
    public class GenericDao<T, ID extends Serializable> extends GenericDAOImpl<T, ID>{
    	protected static final Logger log = LoggerFactory.getLogger(GenericDao.class);
     
    	@PersistenceContext
    	public void setEntityManager(EntityManager entityManager) {
    		super.setEntityManager(entityManager);
    	}
     
    	@Autowired
    	public void setSearchProcessor(JPASearchProcessor searchProcessor) {
    		super.setSearchProcessor(searchProcessor);
    	}
     
    }
    Il faut savoir que GenericDAOImpl proviens de la bibliotheque genericDAO https://code.google.com/p/generic-dao/

    je mets quand mm son code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    public class GenericDAOImpl<T, ID extends Serializable> extends
    		JPABaseDAO implements GenericDAO<T, ID> {
     
    	protected Class<T> persistentClass = (Class<T>) DAOUtil.getTypeArguments(GenericDAOImpl.class, this.getClass()).get(0);
     
    	public int count(ISearch search) {
    		if (search == null)
    			search = new Search();
    		return _count(persistentClass, search);
    	}
     
    	public T find(ID id) {
    		return _find(persistentClass, id);
    	}
     
    	public T[] find(ID... ids) {
    		return _find(persistentClass, ids);
    	}
     
    	public List<T> findAll() {
    		return _all(persistentClass);
    	}
     
    	public void flush() {
    		_flush();
    	}
     
    	public T getReference(ID id) {
    		return _getReference(persistentClass, id);
    	}
     
    	public T[] getReferences(ID... ids) {
    		return _getReferences(persistentClass, ids);
    	}
     
    	public boolean isAttached(T entity) {
    		return _contains(entity);
    	}
     
    	public void refresh(T... entities) {
    		_refresh(entities);
    	}
     
    	public boolean remove(T entity) {
    		return _removeEntity(entity);
    	}
     
    	public void remove(T... entities) {
    		_removeEntities((Object[]) entities);
    	}
     
    	public boolean removeById(ID id) {
    		return _removeById(persistentClass, id);
    	}
     
    	public void removeByIds(ID... ids) {
    		_removeByIds(persistentClass, ids);
    	}
     
    	public T merge(T entity) {
    		return _merge(entity);
    	}
     
    	public T[] merge(T... entities) {
    		return _merge(persistentClass, entities);
    	}
     
    	public void persist(T... entities) {
    		_persist(entities);
    	}
     
    	public T save(T entity) {
    		return _persistOrMerge(entity);
    	}
     
    	public T[] save(T... entities) {
    		return _persistOrMerge(persistentClass, entities);
    	}
     
    	public <RT> List<RT> search(ISearch search) {
    		if (search == null)
    			return (List<RT>) findAll();
    		return _search(persistentClass, search);
    	}
     
    	public <RT> SearchResult<RT> searchAndCount(ISearch search) {
    		if (search == null) {
    			SearchResult<RT> result = new SearchResult<RT>();
    			result.setResult((List<RT>) findAll());
    			result.setTotalCount(result.getResult().size());
    			return result;
    		}
    		return _searchAndCount(persistentClass, search);
    	}
     
    	public <RT> RT searchUnique(ISearch search) {
    		return (RT) _searchUnique(persistentClass, search);
    	}
     
    	public Filter getFilterFromExample(T example) {
    		return _getFilterFromExample(example);
    	}
     
    	public Filter getFilterFromExample(T example, ExampleOptions options) {
    		return _getFilterFromExample(example, options);
    	}
    }
    Je vous remercie d'avance pour toute aide que vous pourriez m'apporter car je galere vraiment depuis une semaine dessus.

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
        <!-- Activates scanning of @Repository -->
        <context:component-scan base-package="com.dao.sem"/>
        <context:component-scan base-package="com.service.sem" />
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    <context:component-scan base-package="com.dao.sem, com.service.sem"/>

    A+.

  3. #3
    Membre éclairé Avatar de amadoulamine1
    Inscrit en
    Avril 2005
    Messages
    260
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 260
    Par défaut
    Bonjour andry.aime . Je vous remercie pour la réponse .

    J'ai essaye mais il me met toujours la meme erreur

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Et ça aussi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <context:component-scan base-package="com.web.sem" />
    Sinon, peut-on voir comment tu charges les fichiers xml et tu peux nous citer un peu plus sur les messages d'erreur?

  5. #5
    Membre éclairé Avatar de amadoulamine1
    Inscrit en
    Avril 2005
    Messages
    260
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 260
    Par défaut
    Bonjour andry.
    Merci pour ton aide.
    Je viens de voir qu'en fait j'avais 2 persistence.xml
    Du coup les modifications que je faisait sur le persistence.mxl n'etaient pas prise en compte car je n'ecrivais pas sur le bon.
    Apres avoir vire le mauvais et fais comme tu as suggere en haut. C'est bon ca marche nickel.

    Encore merci pour ton coup de pouce.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Framework] Erreur "No qualifying bean of type found for dependency"
    Par shark59 dans le forum Spring
    Réponses: 5
    Dernier message: 04/06/2018, 00h55
  2. Réponses: 0
    Dernier message: 09/04/2011, 14h41
  3. [Data] Configuration Spring / JPA / Hibernate
    Par franchouze dans le forum Spring
    Réponses: 0
    Dernier message: 10/11/2009, 15h45
  4. Réponses: 12
    Dernier message: 11/05/2009, 14h51
  5. [Data] Spring + JPA (hibernate) + Tomcat
    Par balteo dans le forum Spring
    Réponses: 1
    Dernier message: 19/11/2007, 11h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo