本文主要是介绍webservice 报错:org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.serv,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景说明:在做spring和apache cxf整合实现webservice的服务端时,启动程序报:
奶奶的,就因为这个问题,解决了一下午。我的pom 文件的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd"><parent><artifactId>web-service-demo</artifactId><groupId>com.meboth.bonc.ljf</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.meboth.bonc.ljf.spring.jax</groupId><artifactId>spring-jax-ws-server</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><name>spring-jax-ws-server Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><!-- 要进行jaxws 服务开发 --><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.1.2</version></dependency><!-- 内置jetty web服务器 --><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>3.1.2</version></dependency><!-- 日志实现 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.25</version></dependency><!--spring 需要的jar包 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.2.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.2.4.RELEASE</version></dependency></dependencies><build><finalName>spring-jax-ws-server</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><!-- maven的jdk编译插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><configuration><source>1.7</source><target>1.7</target><encoding>UTF-8</encoding><showWarnings>true</showWarnings></configuration></plugin><!-- 运行tomcat7方法:tomcat7:run --><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><!-- 指定端口 --><port>8080</port><!-- 请求路径 --><path>/</path></configuration></plugin></plugins></pluginManagement></build>
</project>
查阅了一下午,说是java.servlertapi.jar包冲突,加入下面的依赖得以解决:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
参考地址:https://segmentfault.com/q/1010000008665226/a-1020000008698453
修改后的pom依赖:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd"><parent><artifactId>web-service-demo</artifactId><groupId>com.meboth.bonc.ljf</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.meboth.bonc.ljf.spring.jax</groupId><artifactId>spring-jax-ws-server</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><name>spring-jax-ws-server Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><!-- 要进行jaxws 服务开发 --><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.1.2</version></dependency><!-- 内置jetty web服务器 --><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>3.1.2</version></dependency><!-- 日志实现 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.25</version></dependency><!--spring 需要的jar包 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.2.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.2.4.RELEASE</version></dependency><!-- 解决jar包冲突--><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency></dependencies><build><finalName>spring-jax-ws-server</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><!-- maven的jdk编译插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><configuration><source>1.7</source><target>1.7</target><encoding>UTF-8</encoding><showWarnings>true</showWarnings></configuration></plugin><!-- 运行tomcat7方法:tomcat7:run --><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><!-- 指定端口 --><port>8080</port><!-- 请求路径 --><path>/</path></configuration></plugin></plugins></pluginManagement></build>
</project>
启动项目:
这篇关于webservice 报错:org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.serv的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!