Récupérer un bean dans un interceptor
Bonjour,
J'ai 2 actions dans lesquelles j'injecte un bean via Spring. Une action pour s'authentifier et l'autre pour enregistrer un formulaire.
Pour vérifier si l'utilisateur s'est bien loggué, j'ai créé un interceptor dans lequel il faudrait que je récupère le bean contenant les infos de l'utilisateur. Cependant, ce bean est toujours nul alors que dans mes actions, je récupère bien la bonne instance.
Je commence à perdre patience...
Voici mon fichier applicationContext.xml
Code:
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
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Example of SAF2 action instantiated by Spring -->
<bean id="creationDMPAction" class="com.toto.dmp.action.CreationDMPAction" singleton="false">
<property name="cpsService" ref="cpsService" />
<property name="userCarteCps" ref="userCarteCps" />
</bean>
<bean id="identificationAction" class="com.toto.dmp.action.IdentificationAction" singleton="false">
<property name="cpsService" ref="cpsService" />
<property name="userCarteCps" ref="userCarteCps" />
</bean>
<bean id="cpsService" class="com.toto.dmp.service.impl.CpsServiceImpl" singleton="true">
</bean>
<bean id="userCarteCps" class="com.toto.dmp.beans.UserCarteCps" singleton="false"/>
<bean id="loginCpsInterceptor" class="com.toto.dmp.interceptor.LoginCpsInterceptor" singleton="true">
<property name="cpsService" ref="cpsService" />
<property name="userCarteCps" ref="userCarteCps" />
</bean>
</beans> |
Et mon Struts.xml
Code:
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
| <struts>
<package name="myPackage" extends="struts-default">
<interceptors>
<interceptor name="loginCpsInterceptor" class="com.toto.dmp.interceptor.LoginCpsInterceptor"/>
</interceptors>
<action name="index" class="com.toto.dmp.action.IndexAction">
<result>/jsp/index.jsp</result>
</action>
<action name="creationDMP" class="com.toto.dmp.action.CreationDMPAction">
<interceptor-ref name="createSession"/>
<interceptor-ref name="defaultStack"/>
<result name="input">/jsp/creationDMP.jsp</result>
<result name="error_session">/jsp/index.jsp</result>
<result name="error">/jsp/creationDMP.jsp</result>
<result name="success">/jsp/confirmation.jsp</result>
</action>
<action name="identificationUtilisateur" class="com.toto.dmp.action.IdentificationAction" method="lancerIdentification">
<result name="success">/jsp/creationDMP.jsp</result>
<result name="error">/jsp/index.jsp</result>
<result name="input">/jsp/index.jsp</result>
</action>
<action name="fermerSession" class="com.toto.dmp.action.IdentificationAction" method="fermerSession">
<result name="success">/jsp/index.jsp</result>
<result name="error">/jsp/index.jsp</result>
</action>
</package>
</struts> |
Je récupère donc bien mon instance cpsService dans mon interceptor mais je n'arrive pas à récupérer mon instance du bean userCarteCps alors que dans mes action aucun problème...