码迷,mamicode.com
首页 > 编程语言 > 详细

Maven 创建java Web项目,配置Spring,CXF

时间:2014-06-11 09:08:25      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

 

1.搭建Maven环境

 

参考文章

Maven3路程(一)环境搭建

http://www.cnblogs.com/leiOOlei/p/3359561.html

Maven3路程(二)Eclipse集成Maven

http://www.cnblogs.com/leiOOlei/p/3361379.html

Maven3路程(三)用Maven创建第一个web项目(1)

Maven3路程(三)用Maven创建第一个web项目(2)servlet演示

 

Maven 配置Spring

参考

http://blog.csdn.net/shiyuezhong/article/details/7959863

重点添加这两个依赖

 

bubuko.com,布布扣
 <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
             <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
             <version>3.1.1.RELEASE</version>
        </dependency>
bubuko.com,布布扣

 

 

 

3.Maven 添加 CXF

 

bubuko.com,布布扣
 <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.0.0</version>
    </dependency>
        <!-- Jetty is needed if you‘re are not using the CXFServlet -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
         <version>3.0.0</version>
    </dependency>
bubuko.com,布布扣

 

 

 

 

最后Web.xml文件是这样

bubuko.com,布布扣
<!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>
 <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>
   
     <display-name>Archetype Created Web Application</display-name>
  <!--部署到tomcat中,cxf 的webservice服务就启动了,访问的地址是 xx.com/ws/* -->
   <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXFServlet</display-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>
   
</web-app>
bubuko.com,布布扣

POM.xml文件时这样的

bubuko.com,布布扣
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.webtest</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>test Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>    
        <groupId>javax.servlet</groupId>    
        <artifactId>servlet-api</artifactId>    
        <version>2.5</version>    
        <scope>provided</scope>    
    </dependency>
    

 <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
             <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
             <version>3.1.1.RELEASE</version>
        </dependency>

 <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.0.0</version>
    </dependency>
        <!-- Jetty is needed if you‘re are not using the CXFServlet -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
         <version>3.0.0</version>
    </dependency>
    
  </dependencies>
  <build>
    <finalName>test</finalName>
  </build>
</project>
bubuko.com,布布扣

applicationContext.xml是这样的

bubuko.com,布布扣
<?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxws="http://cxf.apache.org/jaxws" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd 
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<bean id="person" class="test.Person">
       <property name="name" value="zhangsan"></property>
       <property name="age" value="12"></property>
</bean>

<bean id="app" class="test.App">
   <property name="person" ref="person"></property>
</bean>

 <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    
   <bean id="hello" class="test.HelloWorldImpl" />
 
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
    
</beans>
bubuko.com,布布扣

 

 

Maven 创建java Web项目,配置Spring,CXF,布布扣,bubuko.com

Maven 创建java Web项目,配置Spring,CXF

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/zjypp/p/3773029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!