官方文档链接

1、添加起步依赖

<!-- Spring Boot CXF JAX-WS Starter -->
		<dependency>
		    <groupId>org.apache.cxf</groupId>
		    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
		    <version>3.1.12</version>
		</dependency>

2、编写webservice接口

package org.chenhui.study.webservices;

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

@WebService(name = \"helloWebService\", //暴露服务名称
		targetNamespace = \"http://webservices.study.chenhui.org\"  //命名空间,一般是包名的倒序
		)
public interface UserService {
	
	//暴露在webservice接口服务上的方法
	@WebMethod
	public String sayHi();
}

3、实现UserService接口

package org.chenhui.study.webservices.impl;

import javax.jws.WebService;

import org.chenhui.study.webservices.UserService;
import org.spring work.stereotype.Component;

@WebService(serviceName = \"helloWebService\", //web服务名称
		endpointInterface = \"org.chenhui.study.webservices.UserService\",//接口全包名
		targetNamespace = \"http://webservices.study.chenhui.org\")
@Component
public class UserServiceImpl implements UserService{

	@Override
	public String sayHi() {
		System.out.println(\"say Hi!\");
		return \"hello world,spring-boot-ws\";
	}
	
}

4、编写webServiceConfig

package org.chenhui.study.config;

import javax. .ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.chenhui.study.webservices.UserService;
import org.spring work.beans.factory.annotation.Autowired;
import org.spring work.context.annotation.Bean;
import org.spring work.context.annotation.Configuration;

@Configuration
public class WebServiceConfig {
	@Autowired
	private Bus bus;
	
	@Autowired
	private UserService userService;
	
	@Bean
	public Endpoint endpoint(){
		EndpointImpl endpointImpl = new EndpointImpl(bus, userService);
		endpointImpl.publish(\"/HelloService\");
		return endpointImpl;
	}
}

5、启动应用

\"\"

 

报错 。。。 理想很丰满,显示很骨感。报错信息如下


  .   ____          _            __ _ _
 /\\\\ / ___\'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | \'_ | \'_| | \'_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  \'  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2018-12-18 14:33:49.899  INFO 112496 --- [           main] o.c.s.SpringBootWebservicesApplication   : Starting SpringBootWebservicesApplication on Jason with PID 112496 (D:\\ChromeDownload\\spring-boot-webservices\\target\\classes started by jj in D:\\ChromeDownload\\spring-boot-webservices)
2018-12-18 14:33:49.902  INFO 112496 --- [           main] o.c.s.SpringBootWebservicesApplication   : No active profile set, falling back to default profiles: default
2018-12-18 14:33:51.117  INFO 112496 --- [           main] o.s.b.w. ded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-12-18 14:33:51.144  INFO 112496 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-12-18 14:33:51.156  INFO 112496 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-18 14:33:51.169  INFO 112496 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR  d Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\\Program Files\\Java\\jdk1.8.0_92\\bin;C:\\WINDOWS\\Sun\\Java\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;D:\\oracle2\\product\\12.1.0\\dbhome_1\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;D:\\chenH\\redis;D:\\SVN\\VisualSVN-Server-3.9.1-x64\\VisualSVN Server\\bin;D:\\spring\\spring-1.3.0.RELEASE\\bin;D:\\maven\\apache-maven-3.3.9\\bin;C:\\Program Files\\Java\\jdk1.8.0_92\\bin;C:\\Program Files\\Java\\jdk1.8.0_92\\jre\\bin;D:\\Git\\cmd;C:\\Program Files\\nodejs\\;C:\\Users\\jj\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\jj\\AppData\\Roaming\\npm;D:\\Users\\jj\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;.]
2018-12-18 14:33:51.324  INFO 112496 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring  ded WebApplicationContext
2018-12-18 14:33:51.324  INFO 112496 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1371 ms
2018-12-18 14:33:51.411  INFO 112496 --- [           main] o.s.core.annotation.AnnotationUtils      : Failed to introspect annotations on class org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration$$EnhancerBySpringCGLIB$$b5c65915: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2018-12-18 14:33:51.412 ERROR 112496 --- [           main] o.s.b.web. ded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.spring work.beans.factory.BeanCreationException. Message: Error creating bean with name \'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration\': Initialization of bean failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2018-12-18 14:33:51.435  INFO 112496 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-12-18 14:33:51.440  WARN 112496 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.spring work.context.ApplicationContextException: Unable to start web server; nested exception is org.spring work.boot.web.server.WebServerException: Unable to start  ded Tomcat
2018-12-18 14:33:51.447  INFO 112496 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with \'debug\' enabled.
2018-12-18 14:33:51.453 ERROR 112496 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.spring work.context.ApplicationContextException: Unable to start web server; nested exception is org.spring work.boot.web.server.WebServerException: Unable to start  ded Tomcat
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.chenhui.study.SpringBootWebservicesApplication.main(SpringBootWebservicesApplication.java:10) [classes/:na]
Caused by: org.spring work.boot.web.server.WebServerException: Unable to start  ded Tomcat
	at org.spring work.boot.web. ded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:125) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web. ded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web. ded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:414) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web. ded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	... 8 common  s omitted
Caused by: org.spring work.beans.factory.BeanCreationException: Error creating bean with name \'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration\': Initialization of bean failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:235) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:226) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:101) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:88) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:261) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:234) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.spring work.boot.web. ded.tomcat.TomcatStarter. up(TomcatStarter.java:54) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5098) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.util.Lifecycle .start(Lifecycle .java:183) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.Container $StartChild.call(Container .java:1432) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.Container $StartChild.call(Container .java:1422) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_92]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_92]
	at org.apache.catalina.core.Container .startInternal(Container .java:944) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.util.Lifecycle .start(Lifecycle .java:183) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.Container $StartChild.call(Container .java:1432) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.Container $StartChild.call(Container .java:1422) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_92]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_92]
	at org.apache.catalina.core.Container .startInternal(Container .java:944) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.util.Lifecycle .start(Lifecycle .java:183) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.util.Lifecycle .start(Lifecycle .java:183) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:801) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.util.Lifecycle .start(Lifecycle .java:183) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:372) ~[tomcat- -core-9.0.13.jar:9.0.13]
	at org.spring work.boot.web. ded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	... 13 common  s omitted
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_92]
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_92]
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_92]
	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_92]
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_92]
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_92]
	at java.lang.Class.createAnnotationData(Class.java:3521) ~[na:1.8.0_92]
	at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_92]
	at java.lang.Class.createAnnotationData(Class.java:3526) ~[na:1.8.0_92]
	at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_92]
	at java.lang.Class.getAnnotation(Class.java:3415) ~[na:1.8.0_92]
	at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258) ~[na:1.8.0_92]
	at java.lang.Class.isAnnotationPresent(Class.java:3425) ~[na:1.8.0_92]
	at org.spring work.core.annotation.AnnotatedElementUtils.hasAnnotation(AnnotatedElementUtils.java:599) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop.support.annotation.AnnotationClassFilter.matches(AnnotationClassFilter.java:65) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop.support.AopUtils.canApply(AopUtils.java:225) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop.support.AopUtils.canApply(AopUtils.java:288) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop.support.AopUtils.canApply(AopUtils.java:269) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop. work.AbstractAdvisingBeanPostProcessor.isEligible(AbstractAdvisingBeanPostProcessor.java:133) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop. work.AbstractAdvisingBeanPostProcessor.isEligible(AbstractAdvisingBeanPostProcessor.java:115) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop. work.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor.isEligible(AbstractBeanFactoryAwareAdvisingPostProcessor.java:70) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.aop. work.AbstractAdvisingBeanPostProcessor.postProcessAfterInitialization(AbstractAdvisingBeanPostProcessor.java:85) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	at org.spring work.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
	... 58 common  s omitted

其中错误信息包含Error creating bean with name \'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration\',意思是在将CxfAutoConfiguration这个类型装配到springbean容器时报错。问题找到了,那我们就进入这个类一探究竟

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * \"License\"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.cxf.spring.boot.autoconfigure;

import java.util.Map;

import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.spring.SpringComponentScanServer;
import org.apache.cxf.jaxrs.spring.SpringJaxrsClassesScanServer;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.spring work.beans.factory.annotation.Autowired;
import org.spring work.boot.autoconfigure.AutoConfigureAfter;
import org.spring work.boot.autoconfigure.condition.ConditionalOnClass;
import org.spring work.boot.autoconfigure.condition.ConditionalOn ;
import org.spring work.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.spring work.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.spring work.boot.autoconfigure.web. dedServletContainerAutoConfiguration;
import org.spring work.boot.context.properties.EnableConfigurationProperties;
import org.spring work.boot.web.servlet.ServletRegistrationBean;
import org.spring work.context.annotation.Bean;
import org.spring work.context.annotation.Configuration;
import org.spring work.context.annotation.Import;
import org.spring work.context.annotation.ImportResource;

/**
 * {@  org.spring work.boot.autoconfigure.EnableAutoConfiguration Auto-configuration} for Apache CXF.
 *
 * @author Vedran Pavic
 */
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ SpringBus.class, CXFServlet.class })
@EnableConfigurationProperties(CxfProperties.class)
@AutoConfigureAfter( dedServletContainerAutoConfiguration.class)
public class CxfAutoConfiguration {

    @Autowired
    private CxfProperties properties;

    @Bean
    @ConditionalOnMissingBean(name = \"cxfServletRegistration\")
    public ServletRegistrationBean cxfServletRegistration() {
        String path = this.properties.getPath();
        String urlMapping = path.endsWith(\"/\") ? path + \"*\" : path + \"/*\";
        ServletRegistrationBean registration = new ServletRegistrationBean(
                new CXFServlet(), urlMapping);
        CxfProperties.Servlet servletProperties = this.properties.getServlet();
        registration.setLoad up(servletProperties.getLoad up());
        for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
            registration.addInitParameter(entry.getKey(), entry.getValue());
        }
        return registration;
    }

    @Configuration
    @ConditionalOnMissingBean(SpringBus.class)
    @ImportResource(\"classpath: -INF/cxf/cxf. \")
    protected static class SpringBusConfiguration {

    }
    
    @Configuration
    @ConditionalOnClass(JAXRSServerFactoryBean.class)
    @ConditionalOn (\"\'${cxf.jaxrs.component-scan}\'==\'true\' && \'${cxf.jaxrs.classes-scan}\'!=\'true\'\")
    @Import(SpringComponentScanServer.class)
    protected static class JaxRsComponentConfiguration {
     
    }
    
    @Configuration
    @ConditionalOnClass(JAXRSServerFactoryBean.class)
    @ConditionalOn (\"\'${cxf.jaxrs.classes-scan}\'==\'true\' && \'${cxf.jaxrs.component-scan}\'!=\'true\'\")
    @Import(SpringJaxrsClassesScanServer.class)
    protected static class JaxRsClassesConfiguration {
     
    }

}

在源码中我们看到,这个类上加入了@AutoConfigureAfter( dedServletContainerAutoConfiguration.class)注解,@AutoConfigureAfter注解表名这个类需要在 dedServletContainerAutoConfiguration这个类自动配置之后进行自动配置。

然而当我准备进入这个 dedServletContainerAutoConfiguration类的时候,idea没有给我提示,原来根本没有这个类。启动报错的原因就在着了。这种情况第一反应就是兼容问题,下面我将spring-boot的版本调整有2.1.1-->1.5.18

我们再次尝试进入 dedServletContainerAutoConfiguration这个类。\"\"

 

再次启动应用


  .   ____          _            __ _ _
 /\\\\ / ___\'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | \'_ | \'_| | \'_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  \'  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.18.RELEASE)

2018-12-18 14:45:12.060  INFO 116444 --- [           main] o.c.s.SpringBootWebservicesApplication   : Starting SpringBootWebservicesApplication on Jason with PID 116444 (D:\\ChromeDownload\\spring-boot-webservices\\target\\classes started by jj in D:\\ChromeDownload\\spring-boot-webservices)
2018-12-18 14:45:12.062  INFO 116444 --- [           main] o.c.s.SpringBootWebservicesApplication   : No active profile set, falling back to default profiles: default
2018-12-18 14:45:12.101  INFO 116444 --- [           main] ationConfig dedWebApplicationContext : Refreshing org.spring work.boot.context. ded.AnnotationConfig dedWebApplicationContext@35083305: startup date [Tue Dec 18 14:45:12 CST 2018]; root of context hierarchy
2018-12-18 14:45:12.579  INFO 116444 --- [           main] o.s.b.f. . BeanDefinitionReader      : Loading   bean definitions from class path resource [ -INF/cxf/cxf. ]
2018-12-18 14:45:13.195  INFO 116444 --- [           main] s.b.c.e.t.Tomcat dedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-12-18 14:45:13.232  INFO 116444 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-12-18 14:45:13.243  INFO 116444 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.35
2018-12-18 14:45:13.349  INFO 116444 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring  ded WebApplicationContext
2018-12-18 14:45:13.350  INFO 116444 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1251 ms
2018-12-18 14:45:13.597  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: \'dispatcherServlet\' to [/]
2018-12-18 14:45:13.599  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: \'CXFServlet\' to [/services/*]
2018-12-18 14:45:13.603  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'characterEncodingFilter\' to: [/*]
2018-12-18 14:45:13.603  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'hiddenHttpMethodFilter\' to: [/*]
2018-12-18 14:45:13.604  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'httpPutFormContentFilter\' to: [/*]
2018-12-18 14:45:13.604  INFO 116444 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'requestContextFilter\' to: [/*]
2018-12-18 14:45:13.774  INFO 116444 --- [           main] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://webservices.study.chenhui.org}helloWebService from class org.chenhui.study.webservices.UserService
2018-12-18 14:45:14.201  INFO 116444 --- [           main] org.apache.cxf.endpoint.ServerImpl       : Setting the server\'s publish address to be /HelloService
2018-12-18 14:45:14.489  INFO 116444 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.spring work.boot.context. ded.AnnotationConfig dedWebApplicationContext@35083305: startup date [Tue Dec 18 14:45:12 CST 2018]; root of context hierarchy
2018-12-18 14:45:14.549  INFO 116444 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error]}\" onto public org.spring work.http.ResponseEntity<java.util.Map<java.lang.String, java.lang. >> org.spring work.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-12-18 14:45:14.552  INFO 116444 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error],produces=[text/html]}\" onto public org.spring work.web.servlet.ModelAndView org.spring work.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-12-18 14:45:14.580  INFO 116444 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.spring work.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-18 14:45:14.581  INFO 116444 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.spring work.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-18 14:45:14.614  INFO 116444 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.spring work.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-18 14:45:14.729  INFO 116444 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-12-18 14:45:14.770  INFO 116444 --- [           main] s.b.c.e.t.Tomcat dedServletContainer : Tomcat started on port(s): 8080 (http)
2018-12-18 14:45:14.776  INFO 116444 --- [           main] o.c.s.SpringBootWebservicesApplication   : Started SpringBootWebservicesApplication in 2.927 seconds (JVM running for 3.361)

启动成功!!!

收藏 打印