Hi,
i'm pretty new to Spring so bear with me here.
I've got an application configured with Flex on the client side and Java-Spring-Hibernate on the Tomcat server side.
I've been able to set up my configuration to communicate between the Flex and Java however, the remoting calls seem to create new instances of the Java classes, hence, i cannot retrieve already instanciated global variables.
I'm pretty sure all this stems from a wrong bean definition or something of the sort, which is what i'm not good at.
The scenario is as follows: my JSP contains a Flex application. The JSP is associated to a Java controller class which is instanciated as soon as the JSP is displayed. During this initial instanciation, a service variable is instantiated (this service variable will enable me to call a DAO to retrieve data from the database).
Then, following a user action, the Flex calls the Java controller class. The call arrives in the appropriate Java function, which is then supposed to use the service global variable to call a DAO and retrieve data from the database.
Unfortunately, the service variable is null. I believe this is because the remoting call created a new instance of the Java controller class instead of using the already existing one.
I'm pretty sure this is a pretty basic error on my part but i can't seem to find posts anywhere relating to it.
here are my configuration files:
web.xml
Code:<web-app...> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/META-INF/spring/applicationContext-web.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>com.kleegroup.core.boot.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>com.kleegroup.core.managers.monitoring.CounterDispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/META-INF/spring/applicationContext-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet> <servlet-name>flex</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/flex-servlet.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>flex</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> </web-app>
application-context.xml
flex-servlet.xmlCode:<beans...> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"> <property name="autowiredAnnotationType" value="javax.inject.Inject" /> </bean> <!-- Enables the Spring MVC @Controller programming model --> <mvc:annotation-driven /> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/jdbc/DataSource</value> </property> </bean> <!-- Configure the multipart resolver --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> </bean> <!-- Dispatches requests mapped to a MessageBroker --> <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" /> <import resource="applicationContext-monitoring.xml" /> <import resource="applicationContext-hibernate.xml" /> <!-- Généré --> <import resource="applicationContext-domains.xml" /> <import resource="applicationContext-dao.xml" /> <import resource="applicationContext-controllers.xml" /> <!-- Fin Généré --> <import resource="applicationContext-services.xml" /> </beans>
and services-config.xmlCode:<beans ...> <flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml"> <flex:remoting-service default-channels="my-amf" /> </flex:message-broker> </beans>
Code:<?xml version="1.0" encoding="UTF-8"?> <services-config> <channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint class="flex.messaging.endpoints.AMFEndpoint" url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"/> </channel-definition> </channels> <security> <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/> </security> <services> <service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf"/> </default-channels> <destination id="sampleDestination"> <properties> <source>com.kleegroup.proto.ui.controller.flexsample.FlexSampleControllerImpl </source> <scope>session</scope> </properties> </destination> </service> </services> </services-config>
The Java controller class is as follows:
The @Inject annotation on the LigneService enables it to be instantiated by Spring automatically. This is what is lost in the remoting call.Code:@Controller @RequestMapping(FlexSampleController.ADDRESS) public class FlexSampleControllerImpl extends AbstractController implements FlexSampleController { @RequestMapping(method = RequestMethod.GET) @ModelAttribute(AbstractFlexSampleModel.MODEL_NAME) public ModelAndView initModelAndView() { final FlexSampleModel model = new FlexSampleModel(); return forward(DEFAULT_VIEW, model); } @Inject private LigneService ligneService; <- this is the service i need to use which is null when called by Flex public final Collection<LigneBus> getLigneBusList() { final Collection<LigneBus> result = ligneService.getLigneBusList(); return result; } }
Thanks in advance for your insight
Best regards
Pier


Reply With Quote
