WebService 개발 실례 (Xfire + Spring + Hibernate)


본문 발췌: http://blog.csdn.net/caok/archive/2008/12/29/3637734.aspx
 
 
    Xfire 1.2.6, spring 2.0, hibenate 3.0 관련 라 이브 러 리 및 관련 데이터 베 이 스 를 다운로드 하 는 jdbc 드라이브 가 필요 합 니 다.본 논문 의 관련 내용 은 my eclipse 5.1 에서 완성 되 었 다.
 
하나           먼저 웹. xml 에 xfire 및 spring 지원 에 관 한 내용 을 추가 합 니 다. 다음 과 같 습 니 다.
<?xml version="1.0" encoding="ISO-8859-1"?>

 

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<!-- START SNIPPET: xfire -->

<context-param>

<!—xfire spring         -->

 

        <param-name>contextConfigLocation</param-name>

        <param-value>/WEB-INF/applicationContext.xml 

        classpath:org/codehaus/xfire/spring/xfire.xml</param-value>

    </context-param>

 

    <context-param>

        <param-name>log4jConfigLocation</param-name>

        <param-value>/WEB-INF/log4j.properties</param-value>

    </context-param>

    

    <context-param>

        <param-name>webAppRootKey</param-name>

        <param-value>webservicetest.root</param-value>

    </context-param>

 

 

     <filter>

        <filter-name>sessionFilter</filter-name>

        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

    </filter>   

    <filter-mapping>

        <filter-name>sessionFilter</filter-name>

        <url-pattern>/services/*</url-pattern>

    </filter-mapping>        

       

    <listener>

        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

    </listener>

 

    <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>    

      

     <servlet>

        <servlet-name>xfire</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    </servlet>

   

 

    <servlet-mapping>

        <servlet-name>xfire</servlet-name>

        <url-pattern>/services/*</url-pattern>

    </servlet-mapping>       

    

<!-- END SNIPPET: xfire -->

</web-app>

   
 
둘째,           applicationContext. xml 파일 내용:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

 

<!--         -->

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 

    

        <property name="location" value="/WEB-INF/jdbc_connect.properties"/>

        

    </bean>

        

    <!-- C3P0      -->

    

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">     

        

        <property name="driverClass" value="${jdbc.driverClassName}"/>

        <property name="jdbcUrl" value="${jdbc.url}"/>

        <property name="user" value="${jdbc.username}"/>

        <property name="password" value="${jdbc.password}"/>

        

        <property name="initialPoolSize">

            <value>5</value>

        </property>

         <property name="minPoolSize">

             <value>5</value>

         </property>

         <property name="maxPoolSize">

             <value>10</value>

         </property>

         <property name="acquireIncrement">

             <value>2</value>

         </property>

         <property name="maxIdleTime">

             <value>60</value>

         </property>

         <property name="maxStatements">

             <value>0</value>

         </property>     

    </bean> 

    <!-- C3P0   -->

    

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <property name="dataSource" ref="dataSource"/>

        <property name="mappingResources">

            <list>

            <!—hibernate hbm     ,  hbm          ,       -->

                <value>com/dao/emp.hbm.xml</value>              

            </list>

        </property>

        <property name="hibernateProperties">

            <props>

                <prop key="hibernate.dialect">${hibernate.dialect}</prop>       

                <prop key="hibernate.show_sql">true</prop>                  

                <prop key="hibernate.jdbc.fetch_size">100</prop> 

                <prop key="hibernate.jdbc.batch_size">50</prop> 

                <prop key="hibernate.use_outer_join">true</prop>                

                <prop key="hibernate.connection.SetBigStringTryClob">true</prop>

            </props>            

        </property>

        

        <property name="eventListeners">

            <map>

                <entry key="merge">

                    <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>

                </entry>

            </map>

        </property>

    

    </bean>

    

    

    

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

        <property name="sessionFactory" ref="sessionFactory"/>

    </bean>

    

    <bean id="QueryHib" class="Hello.HelloworldImpl ">

        <property name="sessionFactory" ref="sessionFactory"/>

    </bean>

     

    

    <!—webservice  bean  -->

    

    <bean id="QueryHibRis" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

        <property name="transactionManager" ref="transactionManager"/>

        <property name="target" ref="QueryHib"/>

        <property name="transactionAttributes">

            <props>         

            <prop key="*">PROPAGATION_REQUIRED</prop>                   

            </props>

        </property>

    </bean> 

    

</beans>

 

<!-- jdbc_connect.properties    ,        ,   oracle    -->

 

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver

jdbc.url=jdbc:oracle:thin:@172.17.99.230:1521:bsrun

jdbc.username=user

jdbc.password=user

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect


 
4. Hello. Hello World Impl 류 내용 은 주로 데이터 베 이 스 를 조회 하고 결 과 를 되 돌려 줍 니 다.
package Hello;

 

 

import java.util.Collection;

 

//Generated by MyEclipse

 

public class HelloworldImpl implements IHelloworld { 

    

    public Collection User(){   

    return getHibernateTemplate().find("select new Helloworld.User(userid,username) from emp"); 

                

    }

    

}

 

//IHelloworld    

package Hello;

//Generated by MyEclipse

 

import java.util.Collection;

 

 

public interface IHelloworld {

    

    public Collection User();

}


 
//xfire    collection ,       IHelloworld.aegis.xml  ,            。

 

<?xml version="1.0" encoding="UTF-8"?>

 <mappings>

    <mapping>

        <method name= "User" >

            <return-type componentType= "Helloworld.User" />           

        </method>          

        

    </mapping>    

    

</mappings>


 
Helloworld. User 클래스 내용:
package Helloworld;

 

public class User {

    

    String userid;

    String username;

//          , Hello.HelloworldImpl     。

    Public User(String userid,String username){

        this.userid = userid;

this.username = username;

 

}   

 

    public String getUserid() {

        return userid;

    }

    public void setUserid(String userid) {

        this.userid = userid;

    }

    public String getUsername() {

        return username;

    }

    public void setUsername(String username) {

        this.username = username;

    }

 

}

   
 
 
 
 

좋은 웹페이지 즐겨찾기