Bonjour,
Je travaille sur un projet Spring utilisant JPA, Lors de l'appel à une méthode de ma couche DAO, J'ai un NullPointerException sur l'entityManager alors que j'ai l'impression d'voir bien fait les injection de dépendance. Quelqu'un voit -il la faille? Merci.

Mon 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
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
 
<?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"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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-4.2.xsd">
 
   <context:annotation-config></context:annotation-config>
   <context:component-scan base-package="com" />
 
 
   <bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/ma_bdd"></property>
		<property name="username" value="root"></property>
		<property name="password" value=""></property>
	</bean>
 
	<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
		<property name="defaultDataSource" ref="datasource"></property>	
		<property name="persistenceXmlLocations">
		<list>
			<value>classpath*:persistence.xml</value>		
		</list>
		</property>
	</bean>
 
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
		<property name="persistenceUnitName" value="UP_P"></property>
	</bean>
 
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory"></property>
	</bean>
 
	<tx:annotation-driven />
 
</beans>
L'implementation de mon DAO
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
 
@Transactional
@Repository
public class SignUpDAOImpl implements ISignUpDAO {
 
    @PersistenceContext( name = "UP_P" )
    private EntityManager em;
 
    public void setEntityManager( EntityManager entityManager ) {
        this.em = entityManager;
    }
 
    @Override
    @Transactional
    public void register( User user ) {
        em.persist( user );
 
    }
 
    @Override
    public boolean connect( Long id_user ) {
 
        User u = em.find( User.class, id_user );
        if ( u != null ) {
            return true;
        } else {
            return false;
        }
 
    }
 
    @Override
    public void delete( Long id_user ) {
 
        User u = em.find( User.class, id_user );
        em.remove( u );
 
    }
 
    @Override
    public User update( User user ) {
 
        em.merge( user );
        return user;
    }
 
}
Ma class Test
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
 
public class Test {
 
 
    public static void main( String[] args ) {
 
 
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "applicationContext.xml" );
 
 
        ISignUpDAO d = new SignUpDAOImpl();
        User u =new User( "bertrand", "thomas", "berth", "bertra@g.com", "blabla" );
        d.register( u );
 
    }
 
}
Dans la console
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
Exception in thread "main" java.lang.NullPointerException
	at sap.ldee.dao.SignUpDAOImpl.register(SignUpDAOImpl.java:26)
	at sap.ldee.test.Test.main(Test.java:60)