Spring webflow can't access mvc beans
-
28-06-2021 - |
Question
I'm trying to use some @Service annotated classes (yes, using the mvc:annotation-driven) within the following Web flow :
manage-flow.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd" start-state="start" >
<view-state id="start" view="Userview.jsp" >
<on-render>
<set name="flowScope.users"
value="UserService.getUsers()">
</set>
</on-render>
</view-state>
<bean-import resource="Manage-Beans.xml"/>
</flow>
Manage-Beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean class="com.dproductions.test.Service.SiteService" id="SiteService" />
<bean class="com.dproductions.test.Service.CustomerService" id="CustomerService" />
<bean class="com.dproductions.test.Service.UserService" id="UserService" />
</beans>
When attempting to reach the flow I get the following stacktrace : http: //pastebin.com/QmCXe45Y
Which comes down to the Webflow not being able to access the specified package(s). But it doesn't give a 'ClassNotFoundException' , which is sort of puzzling to me.
Any suggestion is welcome.
Besides, my servlet-context is found here : Servlet-context
I've been fighting this for over a week now.
Edit
I want to be able to use my beans the way they are used at This Example , at the action states, the beans being picked up/managed directly by Spring MVC . Do the beans have to be declared (and serializable?) in the applicationcontext ? Using xml-notation ?
Solution
If I change the
<set>
towards an
<evaluate expression>
and have the beans defined in the file Manage-Beans.xml , it works.
But that way I have to define the same bean twice, as it is once picked up by the pkg-search annotation, and then in the web-flow it is again. I'd like to have the beans which are already made.
Spring web flow DOES re-create/instantiate the bean again. You can reference properties, autowire them with beans in the web-flow beans import file, but it's like a new context, unaware of existing beans. (Using events goes to both flow and normal-context files.)
OTHER TIPS
java.lang.IllegalStateException: Exception occurred rendering view org.springframework.web.servlet.view.JstlView: unnamed; URL [/WEB-INF/flows/manage/Userview.jsp] org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:191) org.springframework.webflow.engine.ViewState.render(ViewState.java:296) org.springframework.webflow.engine.ViewState.refresh(ViewState.java:243) org.springframework.webflow.engine.ViewState.resume(ViewState.java:221) org.springframework.webflow.engine.Flow.resume(Flow.java:545) org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258) org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169) org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
Check the view file location.