Bonjour.
Je créé une application JEE avec Struts2, Hibernate4, Spring3 et maven sous eclipse et base de données Oracle.
Lorsque je n'intègre pas spring security, spring charge le context mais lorsque je l'intègre, il ne le charge pas.
Il n'y pas de message d'erreurs mais lorsque je veux utiliser le service (users) dans l'action, je le trouve nul malgré que j'ai mis l'annotaion @Autowired avant le service.
Pour info, je n'utilise pas ldap.
Voici le fichier applicationContext-security.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
51
52
53
 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:sec="http://www.springframework.org/schema/security"
	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"
	xmlns:p="http://www.springframework.org/schema/p"
 
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
 
 
	<sec:debug />
 
	<sec:global-method-security pre-post-annotations="enabled" />
 
 
	<sec:http pattern="/css/**" security="none"/> 
	<sec:http pattern="/img/**" security="none"/>
	<sec:http pattern="/js/**" security="none"/>
	<sec:http pattern="/*login.jsp" security="none"/>
	<sec:http pattern="/*loggedout.jsp" security="none"/>
 
	<sec:http auto-config="true" use-expressions="true">
 
		<sec:intercept-url pattern="/*" access="isAuthenticated()" />
		<sec:intercept-url pattern="/user/*" access="hasRole('USER')" />
		<sec:intercept-url pattern="/admin/*" access="hasRole('ADMIN')" />
 
		<sec:form-login login-processing-url="/resources/j_spring_security_check"
			login-page="/login.jsp"  authentication-failure-url="/login.jsp?login_error=t" default-target-url="/index" />
		<sec:logout logout-url="/resources/j_spring_security_logout" logout-success-url="/login.jsp" />
 
		<sec:session-management>
			<sec:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
		</sec:session-management>
 
 
	</sec:http>
 
 
 
	<bean id="monUserDetailsService" class="fr.monpackage.dao.MonUserDetailsService"/>
 
	<sec:authentication-manager alias="authenticationManager">
        <sec:authentication-provider user-service-ref="monUserDetailsService" />
    </sec:authentication-manager>
 
</beans>
voici le fichier 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
 
<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
 
<context:annotation-config/>
<tx:annotation-driven proxy-target-class="true"/>
 
<context:component-scan base-package="fr.monpackage.*"/>
 
</beans>
Injection du service dans l'action:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
@Autowired
private UsersService usersService = null;
Et dans la classe du service, j'ai ai mis aussi l'annotation comme suit avant la déclaration de la classe:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
@Service("UsersService")
@Transactional
public class UsersServiceImp implements UsersService{...}
Je n'ai pas de message d'erreur avant d'arriver à la ligne d'appel du service qui génère une exception du type
Code : Sélectionner tout - Visualiser dans une fenêtre à part
java.lang.NullPointerException
.
usersService est toujours nul.
Merci par avance pour toute aide de votre part.