cxf框架及ssm综合应用

<!-- applicationContext.xml配置-->

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxw="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!--一定要注意扫描的路径,也不要漏扫描-->
<context:component-scan base-package="com.hd.controll,com.hd.dao.impl,com.hd.service.impl,com.hd.service.impl"></context:component-scan>

<!--引用数据库对应的信息-->
<context:property-placeholder location="classpath:pd.properties"/>


<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driver_Class}"></property>
<property name="jdbcUrl" value="${jbdUrl}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>


<bean id="sqlSesseionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>


<!-- 引入cxf的核心配置文件 -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>


<!-- 发布webservice -->
<jaxw:endpoint id="mywsdl"


<!-- 发布的类的相对路径 -->
implementor="com.hd.release.impl.OrderWsImpl"
address="/wsdlssm">
</jaxw:endpoint>

</beans>

 //mybatis中的配置

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<settings>
<!-- 开启打印sql语句调试模式 -->
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!-- 开启二级缓存 -->
<setting name="cacheEnabled" value="true"/>
</settings>

<typeAliases>
<package name="com.hd.dao.impl"/>
</typeAliases>

<mappers>
<mapper resource="com/hd/dao/impl/OrderDaoImpl.xml"/>
</mappers>

</configuration>

 

 

<!--spring-mvc-tx.xml-->

<!--spring-mvc.xml零配置-->

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<context:component-scan base-package="com.hd.controll"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
<property name="prefix" value="orl/"></property>
</bean>

<!-- 将事务准备捆绑在sessionFactory上-->
<bean id="txmanager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>


<!-- 要做怎样的事务管理 -->
<tx:advice id="txadvice" transaction-manager="txmanager" >
<tx:attributes>
<!-- name是事务切入的方法名 -->
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>


<aop:config>
<!-- aop:pointcut代表需要做事务处理的具体类 -->
<aop:pointcut id="pointcut"
expression="execution(* com.hd.dao.impl.*.*(..))" />
<!-- aop:advisor代表将具体等待做事务的类和具体事务细节组合在一起 -->
<aop:advisor advice-ref="txadvice" pointcut-ref="pointcut"/>
</aop:config>

</beans>

 

//暴露接口的方法

package com.hd.release.impl;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hd.model.Order;
import com.hd.release.IOrderWs;
import com.hd.service.IOrderService;
@WebService
public class OrderWsImpl implements IOrderWs{

@Override
@WebMethod
public List<Order> queryOrderDetail(Order od) {
/**
* 由于现在用的是SSM,spring和springmvc是两套容器,
* 那么他们自个的配置文件的信息并不共享,如果直接发布,spring
* 的dao和其他对象自动注入机制就会失效,所有采用下面这样方式
* 重新组织多个配置文件在一个容器中,得到对应的bean对象
* 通过它调用旧系统中的方法(代理模式的WebService)
*/
ClassPathXmlApplicationContext c =
new ClassPathXmlApplicationContext(
new String[]{"applicationContext.xml",
"spring-mvc-tx.xml",
"spring-mvc.xml"});

IOrderService ios = (IOrderService)c.getBean("orderServiceImpl");
return ios.query(od);
}
}

 

 

<!--service的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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 处理中文乱码问题 start -->
<filter>
<filter-name>UTF-Encoding</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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>UTF-Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- 加载spring环境 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>


<!-- 加载spring MVC环境 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 默认读取web-inf下 [servlet-name]-servlet.xml文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc*.xml</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>





<!-- 加载cxf环境 -->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

</web-app>

 

 

<!--客户端的web配置基本跟服务端一致-->

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>UTF-Encoding</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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UTF-Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
</web-app>

 

<!--client bean-->

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jaxw="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!--client 也要配置扫描文件,如果没有配置,从页面跳转的时候,地址虽然会改变,但是还是会报404的错误-->
<context:component-scan base-package="com.hd.controller"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
</bean>

<jaxw:client
id="wsclient"
serviceClass="com.hd.release.impl.OrderWsImpl"
address="http://localhost:8081/cxf_ssm01/ws/wsdlssm"
/>



</beans>

<!----------------------------------------------------------------------------------------->

//接收暴露出来的数据

package com.hd.controll;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hd.release.impl.Order;
import com.hd.release.impl.OrderWsImpl;

 

@Controller
public class Handler {
@Resource
private OrderWsImpl wsclient;

@RequestMapping("/find.do")
public String getList(Order od,ModelMap m){

List<Order> list = wsclient.queryOrderDetail(null);
m.put("rs", list);
return "orderList";

}

}

 

posted on 2016-11-30 13:13  Joyous丶  阅读(1525)  评论(0编辑  收藏  举报

导航