spring + hibernate + flex 구축

18701 단어 Flex
구축 과정 참고:
http://www.pefj.info/archives/21
나의 환경: spring 3.1
          flex4/flex4.5
          hibernate3.6.1
          jdk1.6
          myeclipse9.0
          tomcat6
구축 과정 이 인터넷 에 많 기 때문에 소개 하지 않 고 많은 사람들 이 튜 토리 얼 을 만 드 는 것 이 잘못 되 었 다.다음은 설정 이 끝 난 프로필 입 니 다:
src 아래:
1.jdbc.property

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/flexmail
jdbc.username=root
jdbc.password=root
jdbc.maxActive=10
jdbc.maxIdle=6
jdbc.maxWait=10000
jdbc.defaultAutoCommit=true
jdbc.poolPreparedStatements=true

2. hibenate 설정 을 spring 설정 파일 src 아래 bean. xml 에 기록 합 니 다.

<?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>
	
<!-- ========================================     ==================================== -->
	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations" value="classpath:jdbc.properties" />
	</bean>
	<bean id="dataSource" destroy-method="close"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" 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"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" 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" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" 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>


3. 웹. xml 동급 디 렉 터 리 에 spring Mvc. xml 를 새로 만 들 었 습 니 다. flex 의 bean 을 관리 하 는 데 사 용 됩 니 다.
<?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"
		class="org.springframework.flex.core.ManageableComponentFactoryBean">
		<constructor-arg
			value="flex.messaging.services.remoting.adapters.JavaAdapter" />
	</bean>
	
	<!--      bean-->
    <flex:message-broker >
	   <flex:remoting-service default-channels="my-amf" />
	</flex:message-broker>

</beans>  

4.web.xml

<?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>


5.WEB-INF/flex/services-config.xml
<?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 class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
        <!-- Uncomment the correct app server
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
		<login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>        
        <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" 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" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://127.0.0.1:8080/shf/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>false</polling-enabled>
            </properties>
        </channel-definition>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfChannel" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                 <polling-enabled>true</polling-enabled>   
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>

        <!--
        <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
        </channel-definition>

        <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>
        -->
    </channels>

    <logging>
        <target class="flex.messaging.log.ConsoleTarget" 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>

7. proxy - config. xml, messaging - config. xml 두 프로필 은 모두 Blazeds 에서 직접 압축 을 풀 었 습 니 다.remoting - config. xml 는 필요 없습니다.
8. 테스트 클래스 쓰기: hibenate 는 테스트 가 없습니다. 배치 할 때 표를 업데이트 하기 때문에 문제 가 없 을 것 입 니 다.
주의해 야 할 것 은 이 테스트 클래스 는 bean. xml 스 캔 한 가방 아래 에 있어 야 합 니 다. 물론 하위 가방 도 가능 합 니 다.
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 호출:

		<!--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>


좋은 웹페이지 즐겨찾기