springboot整合webService CXF时出错

在尝试将SpringBoot与CXF结合创建Web Service的示例中遇到启动错误。问题出现在`endpoint`的bean创建过程中,由于无法加载WebService SEI导致。异常堆栈显示ClassNotFoundException,找不到`foo.service.UserService`类。可能是类路径配置错误或者依赖未正确导入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写了一个springboot整合webService的demo,启动时出错了,希望大牛帮看一下原因,代码如下:

maven依赖:

<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.springbootWebserviceTest</groupId>
  <artifactId>springbootWebserviceTest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springbootWebserviceTest Maven Webapp</name>
  <url>http://maven.apache.org</url>
  
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.4.5.RELEASE</version>
  </parent>
  
  <dependencies>
    <!--支持 Web 应用开发,包含 Tomcat 和 spring-mvc。 -->
     <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
 
  <!-- webservice配置 -->
    <dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-rt-frontend-jaxws</artifactId>
   <version>3.1.6</version>
</dependency>
<dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-rt-transports-http</artifactId>
   <version>3.1.6</version>
</dependency>
    
    <!-- JUnit测试 -->
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      </dependency>
     <!-- spring-test依赖 -->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
      </dependency>
     
      <!--Mybatis-->
      <dependency> 
<groupId>org.mybatis.spring.boot</groupId> 
<artifactId>mybatis-spring-boot-starter</artifactId> 
<version>1.1.1</version> 
 </dependency> 
 
 <!-- 数据库连接池 -->  
       <dependency>  
           <groupId>com.alibaba</groupId>  
           <artifactId>druid</artifactId>  
           <version>1.0.5</version>  
  </dependency>

 <!--支持使用 JDBC 访问数据库-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!-- oracle数据库 -->
        <dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
  </dependencies>
  <build>
  <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
  
    <finalName>springbootWebserviceTest</finalName>
  </build>
  
  <repositories>
      <repository>
          <id>spring-milestone</id>
          <url>https://repo.spring.io/libs-release</url>
      </repository>
  </repositories>
  <pluginRepositories>
      <pluginRepository>
          <id>spring-milestone</id>
          <url>https://repo.spring.io/libs-release</url>
      </pluginRepository>
  </pluginRepositories>
</project>


实体类:

package com.po;
import java.io.Serializable;
public class User implements Serializable{
private static final long serialVersionUID = 1L;

private Integer id;
private String username;
private String password;
private String tel;
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password="
+ password + ", tel=" + tel + ", email=" + email + "]";
}
public User(Integer id, String username, String password, String tel,
String email) {
super();
this.id = id;
this.username = username;
this.password = password;
this.tel = tel;
this.email = email;
}
public User() {
super();
// TODO Auto-generated constructor stub
}
}

dao层:

package com.dao;
import com.po.User;
public interface UserDao {

public String getUsername(Integer id);

public User getUserbyId(Integer id);
}


service类:

package com.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.po.User;

@WebService
public interface UserService {

@WebMethod
String getUsername(@WebParam(name="id")Integer id);

@WebMethod
User getUserByid(Integer id);
}


service实现类:

package com.service.impl;


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


import org.springframework.beans.factory.annotation.Autowired;


import com.dao.UserDao;
import com.po.User;
import com.service.UserService;

@WebService(endpointInterface="foo.service.UserService",targetNamespace="http://service.foo")
public class UserServiceImpl implements UserService {

@Autowired
private UserDao ud;

public UserServiceImpl(){
System.out.println("实体类数据");

}
@Override
@WebMethod
public String getUsername(@WebParam(name = "id") Integer id) {
// TODO Auto-generated method stub
return ud.getUsername(id);
}

@Override
@WebMethod
public User getUserByid(Integer id) {
// TODO Auto-generated method stub
return ud.getUserbyId(id);
}
}

config类:

package com.conf;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.service.UserService;
import com.service.impl.UserServiceImpl;

@Configuration
public class WebServiceConfig {


@Bean
public ServletRegistrationBean dispatcherServlet(){

return new ServletRegistrationBean(new CXFServlet(), "/test/*");
}

@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus(){
return new SpringBus();
}

@Bean
public UserService userService(){
return new UserServiceImpl();
}

@Bean
public Endpoint endpoint(){
EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
endpoint.publish("/user");

return endpoint;
}
}

启动:

package com;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.dao")
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
System.out.println("hehehe!");
}
}

启动时报错如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'endpoint' defined in class path resource [com/conf/WebServiceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'endpoint' threw exception; nested exception is javax.xml.ws.WebServiceException: javax.xml.ws.WebServiceException: Could not load Webservice SEI
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at com.Application.main(Application.java:12) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'endpoint' threw exception; nested exception is javax.xml.ws.WebServiceException: javax.xml.ws.WebServiceException: Could not load Webservice SEI
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 18 common frames omitted
Caused by: javax.xml.ws.WebServiceException: javax.xml.ws.WebServiceException: Could not load Webservice SEI
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:375) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:255) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
at com.conf.WebServiceConfig.endpoint(WebServiceConfig.java:38) ~[classes/:na]
at com.conf.WebServiceConfig$$EnhancerBySpringCGLIB$$3028225.CGLIB$endpoint$1(<generated>) ~[classes/:na]
at com.conf.WebServiceConfig$$EnhancerBySpringCGLIB$$3028225$$FastClassBySpringCGLIB$$901e6eb9.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at com.conf.WebServiceConfig$$EnhancerBySpringCGLIB$$3028225.endpoint(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 19 common frames omitted
Caused by: javax.xml.ws.WebServiceException: Could not load Webservice SEI
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplementorInfo.java:301) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplementorInfo.java:60) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:403) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:338) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
... 31 common frames omitted
Caused by: java.lang.ClassNotFoundException: foo.service.UserService
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_80]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_80]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_80]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_80]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[na:1.7.0_80]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_80]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[na:1.7.0_80]
at org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass2(ClassLoaderUtils.java:287) ~[cxf-core-3.1.6.jar:3.1.6]
at org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:261) ~[cxf-core-3.1.6.jar:3.1.6]
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplementorInfo.java:299) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
... 34 common frames omitted


请指教!!!

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值