Integration of flex with spring and Hibernate

Source: Internet
Author: User

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

  1. Package com. Fire. Spring;
  2. Import org. springframework. Context. applicationcontext;
  3. Import org. springframework. Web. Context. Support. webapplicationcontextutils;
  4. Import org. springframework. Beans. beansexception;
  5. Import org. springframework. Beans. Factory. nosuchbeandefinitionexception;
  6. Import Flex. messaging. factoryinstance;
  7. Import Flex. messaging. flexfactory;
  8. Import Flex. messaging. config. configmap;
  9. Import Flex. messaging. Services. serviceexception;
  10. Public class springfactory implements flexfactory
  11. {
  12. Private Static final string source = "Source ";
  13. Public void initialize (string ID, configmap ){}
  14. Public factoryinstance createfactoryinstance (string ID, configmap properties)
  15. {
  16. Springfactoryinstance instance = new springfactoryinstance (this, ID, properties );
  17. Instance. setsource (properties. getpropertyasstring (source, instance. GETID ()));
  18. Return instance;
  19. } // End method createfactoryinstance ()
  20. Public object Lookup (factoryinstance insT)
  21. {
  22. Springfactoryinstance factoryinstance = (springfactoryinstance) inst;
  23. Return factoryinstance. Lookup ();
  24. }
  25. Static class springfactoryinstance extends factoryinstance
  26. {
  27. Springfactoryinstance (springfactory factory, string ID, configmap properties)
  28. {
  29. Super (factory, ID, properties );
  30. }
  31. Public String tostring ()
  32. {
  33. Return "springfactory instance for id =" + GETID () + "Source =" + getsource () + "scope =" + getscope ();
  34. }
  35. Public object Lookup ()
  36. {
  37. Applicationcontext appcontext = webapplicationcontextutils. getwebapplicationcontext (Flex. messaging. flexcontext. getservletconfig (). getservletcontext ());
  38. String beanname = getsource ();
  39. Try
  40. {
  41. Return appcontext. getbean (beanname );
  42. }
  43. Catch (nosuchbeandefinitionexception nexc)
  44. {
  45. Serviceexception E = new serviceexception ();
  46. String MSG = "Spring service named" + beanname + "'does not exist .";
  47. E. setmessage (MSG );
  48. E. setrootcause (nexc );
  49. E. setdetails (MSG );
  50. E. setcode ("server. Processing ");
  51. Throw E;
  52. }
  53. Catch (beansexception bexc)
  54. {
  55. Serviceexception E = new serviceexception ();
  56. String MSG = "unable to create spring service named '" + beanname + "'";
  57. E. setmessage (MSG );
  58. E. setrootcause (bexc );
  59. E. setdetails (MSG );
  60. E. setcode ("server. Processing ");
  61. Throw E;
  62. }
  63. }
  64. }
  65. }

Configure the WEB-INF/flex/service-config.xml and add the following code at the end:

XML Code

XML Code

  1. <Factories>
  2. <Factory id = "Spring" class = "com. Fire. Spring. springfactory"/>
  3. Factories>

When you configure the remote-config.xml when using remoteobject, configure as follows:

XML Code

  1. <Destination ID = "provinceservice">
  2. <Properties>
  3. <Factory> spring </factory>
  4. <Source> provinceservice </source>
  5. </Properties>
  6. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.