Bonjour à tous,
Je mets en place un nouveau projet utilisant struts / spring / hibernate.
J'ai un soucis lorsque j'accède à ma classe Action, le système me dit que ma classe Action n'est pas du bon type...
La méthode de couplage retenu entre struts et spring est la "délégation d'action".
la trace obtenue :
mon descripteur de déploiement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/intranet].[action] - "Servlet.service()" pour la servlet action a généré une exception org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named '/rechercheUserAction' must be of type [org.apache.struts.action.Action], but was actually of type [$Proxy6] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:313) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:165) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:646) at org.springframework.web.struts.DelegatingActionProxy.getDelegateAction(DelegatingActionProxy.java:122) at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:413) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:225) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
définition de mon action :
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 <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>Acegi Filter Chain Proxy</filter-name> <filter-class> org.acegisecurity.util.FilterToBeanProxy </filter-class> <init-param> <param-name>targetBean</param-name> <param-value>filterChainProxy</param-value> </init-param> </filter> <filter-mapping> <filter-name>Acegi Filter Chain Proxy</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>Hibernate Session In View Filter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name>Hibernate Session In View Filter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/config/spring-securite.xml, /WEB-INF/config/spring-jmx.xml, /WEB-INF/config/aop-context.xml, /WEB-INF/config/spring-dao-datasource.xml,/WEB-INF/config/spring-dao-context.xml, /WEB-INF/config/spring-dao-commun.xml,/WEB-INF/config/spring-dao-annexe.xml,/WEB-INF/config/spring-services-annexe.xml, /WEB-INF/config/spring-services-commun.xml </param-value> </context-param> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/config/struts-config_commun.xml, /WEB-INF/config/struts-config_client.xml, /WEB-INF/config/struts-config_produit.xml, /WEB-INF/config/struts-config_annexe.xml </param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- chargement des librairies de tags --> ... </jsp-config> </web-app>
voici mon action :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <action path="/rechercheUserAction" type="org.springframework.web.struts.DelegatingActionProxy" parameter="method" scope="request"> <forward name="vueUser" path="/vues/commun/jsp/vueUser.jsp"/> </action>
ma classe service :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public class RechercheUserAction extends DispatchAction{ private RechercheUserServiceInterface rechercheUserService=null; public void setRechercheUserService(RechercheUserServiceInterface userService) { this.rechercheUserService = userService; } public ActionForward cherche( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ request.setAttribute("userResult", this.getRechercheUserService().getUserByLogin("sadam") ); return mapping.findForward("vueUser"); } }
les défs de bean spring :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class RechercheUserService implements RechercheUserServiceInterface{ private UserDao userDao; public User getUserByLogin( String login ) throws Exception{ User userTest = this.userDao.get(login); return userTest; } // pour IOC public void setUserDao(UserDao userDao) { this.userDao = userDao; } }
Si vous avez une idée, elle est la bien venue....
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 <bean name="/rechercheUserAction" class="fr.proximit.igns.action.commun.RechercheUserAction"> <property name="rechercheUserService"> <ref local="rechercheUserService" /> </property> </bean> <bean id="rechercheUserServiceTarget" class="fr.proximit.igns.service.commun.RechercheUserService"> <property name="userDao"> <ref bean="userDao" /> </property> </bean> <bean id="rechercheUserService" parent="transactionProxy"> <property name="target"> <ref bean="rechercheUserServiceTarget" /> </property> </bean> <bean id="transactionProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager"/> </property> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>
Merci beaucoup
Partager