The flex background uses spring + hibernate. The Integration Method of spring + Hibernate is the same as that in the J2EE project. Mainly integration of flex and spring
Compile springfactory. Java class:
Java code
- Package com. Fire. Spring;
- Import org. springframework. Context. applicationcontext;
- Import org. springframework. Web. Context. Support. webapplicationcontextutils;
- Import org. springframework. Beans. beansexception;
- Import org. springframework. Beans. Factory. nosuchbeandefinitionexception;
- Import Flex. messaging. factoryinstance;
- Import Flex. messaging. flexfactory;
- Import Flex. messaging. config. configmap;
- Import Flex. messaging. Services. serviceexception;
- Public class springfactory implements flexfactory
- {
- Private Static final string source = "Source ";
- Public void initialize (string ID, configmap ){}
- Public factoryinstance createfactoryinstance (string ID, configmap properties)
- {
- Springfactoryinstance instance = new springfactoryinstance (this, ID, properties );
- Instance. setsource (properties. getpropertyasstring (source, instance. GETID ()));
- Return instance;
- } // End method createfactoryinstance ()
- Public object Lookup (factoryinstance insT)
- {
- Springfactoryinstance factoryinstance = (springfactoryinstance) inst;
- Return factoryinstance. Lookup ();
- }
- Static class springfactoryinstance extends factoryinstance
- {
- Springfactoryinstance (springfactory factory, string ID, configmap properties)
- {
- Super (factory, ID, properties );
- }
- Public String tostring ()
- {
- Return "springfactory instance for id =" + GETID () + "Source =" + getsource () + "scope =" + getscope ();
- }
- Public object Lookup ()
- {
- Applicationcontext appcontext = webapplicationcontextutils. getwebapplicationcontext (Flex. messaging. flexcontext. getservletconfig (). getservletcontext ());
- String beanname = getsource ();
- Try
- {
- Return appcontext. getbean (beanname );
- }
- Catch (nosuchbeandefinitionexception nexc)
- {
- Serviceexception E = new serviceexception ();
- String MSG = "Spring service named" + beanname + "'does not exist .";
- E. setmessage (MSG );
- E. setrootcause (nexc );
- E. setdetails (MSG );
- E. setcode ("server. Processing ");
- Throw E;
- }
- Catch (beansexception bexc)
- {
- Serviceexception E = new serviceexception ();
- String MSG = "unable to create spring service named '" + beanname + "'";
- E. setmessage (MSG );
- E. setrootcause (bexc );
- E. setdetails (MSG );
- E. setcode ("server. Processing ");
- Throw E;
- }
- }
- }
- }
Configure the WEB-INF/flex/service-config.xml and add the following code at the end:
XML Code
XML Code
- <Factories>
- <Factory id = "Spring" class = "com. Fire. Spring. springfactory"/>
- Factories>
When you configure the remote-config.xml when using remoteobject, configure as follows:
XML Code
- <Destination ID = "provinceservice">
- <Properties>
- <Factory> spring </factory>
- <Source> provinceservice </source>
- </Properties>
- </Destination>
Note: The above content comes from the Internet and I am not liable for any joint liability.
Article from: http://www.daoyu.com /? P = 72