spring +hibernate+flex搭建
搭建过程参考:http://www.pefj.info/archives/21
我的环境:spring3.1
flex4/flex4.5
hibernate3.6.1
jdk1.6
myeclipse9.0
tomcat6
因为搭建过程网上很多,就不介绍,很多人教程搭建还是出错。下面是配置完之后的配置文件:
src下面:
1.jdbc.property
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc\:mysql\://localhost\:3306/flexmailjdbc.username=rootjdbc.password=rootjdbc.maxActive=10jdbc.maxIdle=6jdbc.maxWait=10000jdbc.defaultAutoCommit=truejdbc.poolPreparedStatements=true
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:flex="http://www.springframework.org/schema/flex"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "><!-- ==========================annotation写 @Component,service 扫描的包====================================== --><context:annotation-config /><context:component-scan base-package="com.flex"></context:component-scan><!-- ========================================连接池配置==================================== --><beanvalue="classpath:jdbc.properties" /></bean><bean id="dataSource" destroy-method="close"value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="maxActive" value="${jdbc.maxActive}" /><property name="maxIdle" value="${jdbc.maxIdle}" /><property name="maxWait" value="${jdbc.maxWait}" /><property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" /><property name="poolPreparedStatements" value="${jdbc.poolPreparedStatements}" /></bean><!--=============================== 配置SessionFactory===================================== --><bean id="sessionFactory"ref="dataSource" /><property name="packagesToScan"><list><value>com.agoni.OA.model</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop><!--<prop key="hibernate.current_session_context_class">thread</prop> --></props></property></bean><!--==============================配置事务管理器以及切面========================================= --><bean id="hibernateTemplate" ref="sessionFactory"></property></bean><bean id="txManager"ref="sessionFactory" /></bean><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="find*" read-only="true" propagation="REQUIRED"/><tx:method name="serach*" propagation="REQUIRED"/><tx:method name="add*" propagation="REQUIRED"/><tx:method name="update*" propagation="REQUIRED"/><tx:method name="modify*" propagation="REQUIRED"/><tx:method name="delete*" propagation="REQUIRED"/><tx:method name="*" propagation="REQUIRED" rollback-for="Throwable.class" /></tx:attributes></tx:advice><aop:config><aop:pointcut expression="execution(public * com.flexmail.service..*.*(..))"id="servicePointcut" /><aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice" /></aop:config> </beans>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:flex="http://www.springframework.org/schema/flex" 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 http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd"><bean id="javaAdapter"/></bean><!--注解方式注入bean--> <flex:message-broker > <flex:remoting-service default-channels="my-amf" /></flex:message-broker></beans>
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version="2.5"><display-name>BlazeDS</display-name><description>BlazeDS Application</description><!-- =========================== 错误页面 配置====================================== --><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file></welcome-file-list><error-page><error-code>404</error-code><location>/404.jsp</location></error-page><error-page><error-code>500</error-code><location>/error.jsp</location></error-page><!-- ============================spring 配置====================================== --><context-param id="spring"><param-name>contextConfigLocation</param-name><param-value>classpath:beans.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- ============================hibernate 配置====================================== --><filter><filter-name>openSessionInView</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class><init-param><param-name>singleSession</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>openSessionInView</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- ============================编码 配置====================================== --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- ============================flex的所有 配置====================================== --><!-- Http Flex Session attribute and binding listener support --><listener><listener-class>flex.messaging.HttpFlexSession</listener-class></listener><servlet><servlet-name>MessageBrokerServle</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springMvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>MessageBrokerServle</servlet-name><url-pattern>/spring/*</url-pattern></servlet-mapping></web-app>
<?xml version="1.0" encoding="UTF-8"?><services-config> <services> <service-include file-path="proxy-config.xml" /> <service-include file-path="messaging-config.xml" /> <default-channels> <channel ref="my-amf"/> </default-channels> </services> <security> <login-command server="Tomcat"/> <!-- Uncomment the correct app server <login-command server="JBoss"><login-command server="JRun"/> <login-command server="Weblogic"/> <login-command server="WebSphere"/> --> <!-- <security-constraint id="basic-read-access"> <auth-method>Basic</auth-method> <roles> <role>guests</role> <role>accountants</role> <role>employees</role> <role>managers</role> </roles> </security-constraint> --> </security> <channels> <channel-definition id="my-amf" level="Error"> <properties> <prefix>[BlazeDS] </prefix> <includeDate>false</includeDate> <includeTime>false</includeTime> <includeLevel>false</includeLevel> <includeCategory>false</includeCategory> </properties> <filters> <pattern>Endpoint.*</pattern> <pattern>Service.*</pattern> <pattern>Configuration</pattern> </filters> </target> </logging> <system> <redeploy> <enabled>false</enabled> <!-- <watch-interval>20</watch-interval> <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file> <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file> <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file> <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file> <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file> <touch-file>{context.root}/WEB-INF/web.xml</touch-file> --> </redeploy> </system></services-config>
import org.springframework.flex.remoting.RemotingDestination;import org.springframework.stereotype.Service;@Service("myService")@RemotingDestination(channels={"my-amf"})public class MyService {public String sayHello(String name) { System.out.println(name); return "hello "+name;}}
<!--flex 与普通java类通信--><s:RemoteObject id="say" destination="myService"endpoint="http://127.0.0.1:8080/shf/spring/messagebroker/amf" result="resultHandler(event)" fault="faultHandler(event)"></s:RemoteObject>