大黄瓜de冬天 2022-02-22 13:44 采纳率: 88.9%
浏览 136
已结题

springboot整合webservice,启动报端口占用错误

问题遇到的现象和发生背景

项目是springboot项目,整合webservice服务端和客户端时报端口占用。

问题相关代码,请勿粘贴截图
@WebService(name="TestUserService",targetNamespace="http://service.erpJlb.jianlibao.com")
@Component
public interface TestUserService {

    @WebMethod
    public TestUser getTestUser(@WebParam(name = "name") String name);

    @WebMethod
    @WebResult(name="String",targetNamespace="")
    public String getUserName(@WebParam(name = "name") String name);

}

@WebService(serviceName="TestUserService",//对外发布的服务名
            targetNamespace="http://service.erpJlb.jianlibao.com",//指定你想要的名称空间,通常使用使用包名反转
            endpointInterface="com.jianlibao.erpJlb.service.TestUserService")//服务接口全路径, 指定做SEI(Service EndPoint Interface)服务端点接口
@Component
public class TestUserServiceImpl implements TestUserService {

    private Map<Long, TestUser> userMap = new HashMap<Long, TestUser>();

    @Override
    public TestUser getTestUser(String name) {
        return userMap.get(name);
    }

    @Override
    public String getUserName(String name) {
        return "name为:" + name;
    }

    public TestUserServiceImpl() {
        System.out.println("向实体类插入数据");
        TestUser testUser = new TestUser();
        testUser.setUserId(SnowflakeIdWorker.generateId());
        testUser.setName("小红");
        testUser.setAge("20");
        userMap.put(testUser.getUserId(), testUser);
    }
}

@Configuration
public class CxfConfig {

    @Autowired
    private Bus bus;

    @Autowired
    private TestUserService testUserService;

    /**
     * 此方法作用是改变项目中服务名的前缀名,此处127.0.0.1或者localhost不能访问时,请使用ipconfig查看本机ip来访问
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl
     * 去掉注释后:wsdl访问地址为:http://127.0.0.1:8080/soap/user?wsdl
     * @return
     */
    @SuppressWarnings("all")
    @Bean
    public ServletRegistrationBean aaaaaa() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }

    /** JAX-WS
     * 站点服务
     * **/
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, testUserService);
        endpoint.publish("/testUser");
        return endpoint;
    }
}

pom文件
<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.1.11</version>
        </dependency>
运行结果及报错内容
Connected to the target VM, address: '127.0.0.1:53835', transport: 'socket'
Application Version: 1.0.0
Spring Boot Version: 2.2.13.RELEASE

13:19:21.253 [background-preinit] INFO  o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.0.22.Final
13:19:21.300 [restartedMain] INFO  c.j.JianLiBaoApplication - [logStarting,55] - Starting JianLiBaoApplication on LAPTOP-EIBFNEMF with PID 16164 (E:\workSpace\jlb-api\JianLiBao-api\jianlibao\jianlibao-admin\target\classes started by 高印-胡水 in E:\workSpace\jlb-api\JianLiBao-api\jianlibao)
13:19:21.300 [restartedMain] INFO  c.j.JianLiBaoApplication - [logStartupProfileInfo,655] - The following profiles are active: druid
13:19:25.490 [restartedMain] ERROR o.s.b.SpringApplication - [reportFailure,826] - Application run failed
java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration]
    at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334)
    at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:446)
    at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:369)
    at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:284)
    at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193)
    at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106)
    at org.springframework.context.annotation.AnnotationConfigUtils.attributesFor(AnnotationConfigUtils.java:285)
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:102)
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:81)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.registerBeanDefinitionForImportedConfigurationClass(ConfigurationClassBeanDefinitionReader.java:160)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.jianlibao.JianLiBaoApplication.main(JianLiBaoApplication.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:144)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
    at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:324)
    ... 29 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:53835', transport: 'socket'

Process finished with exit code 0
我的解答思路和尝试过的方法

尝试了进程查找,但启动的时候才会出现端口且时随机的;想给webservice设置一个端口,网上搜了但没找到我需要的答案;还有个奇怪的现象有时候可以启动,

我想要达到的结果

1.给webservice设置一个端口,使他们启动时不冲突
2.不设置端口,但解决单口占用
以上任其一都非常nice了

  • 写回答

2条回答 默认 最新

  • yuye9427 2022-02-22 14:00
    关注

    你这个不是端口号的问题,应该是注入对象的事,把类里的东西全注掉,然后放开部分重启,看到哪步出错就是了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月2日
  • 已采纳回答 2月22日
  • 创建了问题 2月22日

悬赏问题

  • ¥15 notepad++ 自动补全提示,如输入汉字"人名",就会出现"张三","李四"
  • ¥15 如何用matlab实现PSO算法与两种智能优化算法在30维和50维问题上的性能比较?
  • ¥15 在qt的QGraphicsView和QGraphicsScene中遇到的问题
  • ¥50 如何完美解决谷歌礼品卡支付不被检测
  • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
  • ¥15 arduino上连sim900a实现连接mqtt服务器
  • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
  • ¥66 关于人体营养与饮食规划的线性规划模型
  • ¥15 基于深度学习的快递面单识别系统