SpringBoot 1.4升級中遇到的奇葩問題

截止寫這片內(nèi)容時刁岸,springboot的最新版本是1.4 塞颁,現(xiàn)在項目中使用的springboot版本是1.3.5走贪,jdk環(huán)境是1.7。在升級springboot從1.3.5升級到1.4的時候出現(xiàn)了一些小問題缰盏,這里記錄下來涌萤。

log4j變成log4j2

在我使用的1.3.5版本的boot的使用的是log4j,在boot1.4的版本中乳规,就需要使用log4j2形葬,否則會出現(xiàn)如下錯誤合呐,


image

解決方法如下暮的,更改依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

jetty的支持

在1.3.5的時候使用jetty的時候在pom中直接依賴,如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
<dependency>

但是在1.4.0中淌实,這個貌似不行了冻辩,會出現(xiàn)下面錯誤:

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

23:09:53.110 [main] INFO  com.test.Startup - Starting Startup on zhaoiang-PC with PID 10164 (E:\Simple\testJetty\target\classes started by Administrator in E:\Simple\testJetty)
23:09:53.112 [main] INFO  com.test.Startup - No active profile set, falling back to default profiles: default
23:09:53.125 [background-preinit] INFO  org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final
23:09:53.176 [main] INFO  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@145b2a9a: startup date [Mon Sep 05 23:09:53 CST 2016]; root of context hierarchy
23:09:54.438 [main] WARN  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
23:09:54.448 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at com.test.Startup.main(Startup.java:9) [classes/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    ... 8 more

看意思應該是少了bean,經(jīng)查詢發(fā)現(xiàn)拆祈,需要自己手動的配置bean factory恨闪,如下:

package com.test;

import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyConfig {
    
    public @Bean JettyEmbeddedServletContainerFactory servletContainer() {
        JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
        return factory;
    }
}

不知道為什么需要這樣做,以前的不是挺好的嗎放坏,如果你想到其他的方法可以聯(lián)系我郵箱:601476362@qq.com咙咽。

jetty9.3依賴jdk8
著上面做完了以后,有發(fā)現(xiàn)另外一個問題淤年,如下:

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

23:13:39.598 [main] INFO  com.test.Startup - Starting Startup on zhaoiang-PC with PID 9672 (E:\Simple\testJetty\target\classes started by Administrator in E:\Simple\testJetty)
23:13:39.600 [main] INFO  com.test.Startup - No active profile set, falling back to default profiles: default
23:13:39.613 [background-preinit] INFO  org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final
23:13:39.664 [main] INFO  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@73d7d107: startup date [Mon Sep 05 23:13:39 CST 2016]; root of context hierarchy
23:13:40.937 [main] WARN  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletContainer' defined in class path resource [com/test/MyConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'servletContainer' threw exception; nested exception is java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
23:13:40.948 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletContainer' defined in class path resource [com/test/MyConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'servletContainer' threw exception; nested exception is java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at com.test.Startup.main(Startup.java:9) [classes/:?]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletContainer' defined in class path resource [com/test/MyConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'servletContainer' threw exception; nested exception is java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:199) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    ... 8 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'servletContainer' threw exception; nested exception is java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:199) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    ... 8 more
Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.7.0_71]
    at java.lang.ClassLoader.defineClass(Unknown Source) ~[?:1.7.0_71]
    at java.security.SecureClassLoader.defineClass(Unknown Source) ~[?:1.7.0_71]
    at java.net.URLClassLoader.defineClass(Unknown Source) ~[?:1.7.0_71]
    at java.net.URLClassLoader.access$100(Unknown Source) ~[?:1.7.0_71]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_71]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_71]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_71]
    at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.7.0_71]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_71]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[?:1.7.0_71]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_71]
    at com.test.MyConfig.servletContainer(MyConfig.java:11) ~[classes/:?]
    at com.test.MyConfig$EnhancerBySpringCGLIB$c757767c.CGLIB$servletContainer$0() ~[classes/:?]
    at com.test.MyConfig$EnhancerBySpringCGLIB$c757767c$FastClassBySpringCGLIB$8b26747d.invoke() ~[classes/:?]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at com.test.MyConfig$EnhancerBySpringCGLIB$c757767c.servletContainer() ~[classes/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:199) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    ... 8 more

這很明顯钧敞,就是jdk版本不符合蜡豹,初步排查因為springboot 1.4默認引用的jetty版本是9.3的,同時jetty9.3依賴jdk8溉苛,因此才會出現(xiàn)上面問題镜廉。下面是官方的版本定義:


image

解決方法:

如果可以升級jdk就可以徹底解決上面問題;如果不能升級jdk則可以使用下面方法:

  1. 在properties標簽中中增加jetty的版本號引用愚战。
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jetty.version>8.1.15.v20140411</jetty.version>
    <jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
</properties>
  1. 在dependency中排除掉‘org.eclipse.jetty.websocket’的所有引用
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.jetty.websocket</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

ok娇唯,到此位置,啟動解決問題寂玲。啟動測試塔插,如下:

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

23:56:51.726 [main] INFO  com.test.Startup - Starting Startup on zhaoiang-PC with PID 35052 (E:\Simple\SpringBoot1.4AndJetty\target\classes started by Administrator in E:\Simple\SpringBoot1.4AndJetty)
23:56:51.728 [main] INFO  com.test.Startup - No active profile set, falling back to default profiles: default
23:56:51.744 [background-preinit] INFO  org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final
23:56:51.793 [main] INFO  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@44343ad1: startup date [Mon Sep 05 23:56:51 CST 2016]; root of context hierarchy
23:56:53.881 [main] INFO  org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory - Server initialized with port: 8080
23:56:53.885 [main] INFO  org.eclipse.jetty.server.Server - jetty-8.1.15.v20140411
23:56:53.933 [main] INFO  application - Initializing Spring embedded WebApplicationContext
23:56:53.934 [main] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 2144 ms
23:56:54.176 [main] INFO  org.springframework.boot.web.servlet.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
23:56:54.182 [main] INFO  org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
23:56:54.184 [main] INFO  org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
23:56:54.185 [main] INFO  org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
23:56:54.185 [main] INFO  org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
23:56:54.524 [main] INFO  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@44343ad1: startup date [Mon Sep 05 23:56:51 CST 2016]; root of context hierarchy
23:56:54.626 [main] INFO  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
23:56:54.627 [main] INFO  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
23:56:54.670 [main] INFO  org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
23:56:54.670 [main] INFO  org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
23:56:54.717 [main] INFO  org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
23:56:55.116 [main] INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
23:56:55.144 [main] INFO  application - Initializing Spring FrameworkServlet 'dispatcherServlet'
23:56:55.144 [main] INFO  org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization started
23:56:55.165 [main] INFO  org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization completed in 21 ms
23:56:55.198 [main] INFO  org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@0.0.0.0:8080
23:56:55.199 [main] INFO  org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer - Jetty started on port(s) 8080
23:56:55.208 [main] INFO  com.test.Startup - Started Startup in 3.978 seconds (JVM running for 4.849)

testing的改變

在開發(fā)的時候我們經(jīng)常需要進行單元測試,如果是開發(fā)web項目的時候還需要對http接口進行測試拓哟,在springboot1.3.5版本的時候我們只需要在test class上配置如下

package ess.api;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import ess.Startup;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Startup.class)
@WebIntegrationTest
public class MyTest2 {
    @Test
    public void test() {
        
    }

}

但是這個代碼升級到了1.4.1版本的時候出現(xiàn)了deprecated佑淀,就是說這種注解配置過時了,可能會在未來的某個版本取消掉彰檬,因此可以改成如下

package ess.api;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

import ess.Startup;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Startup.class,webEnvironment = WebEnvironment.DEFINED_PORT)
public class MyTest2 {
    @Test
    public void test() {
        
    }

}

這樣就ok了伸刃,更多可以參考 http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-testing 官方文檔。

源代碼下載:http://git.oschina.net/xiaoqiangge/SpringBoot1.4AndJetty

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末逢倍,一起剝皮案震驚了整個濱河市捧颅,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌较雕,老刑警劉巖碉哑,帶你破解...
    沈念sama閱讀 212,816評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異亮蒋,居然都是意外死亡扣典,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,729評論 3 385
  • 文/潘曉璐 我一進店門慎玖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來贮尖,“玉大人,你說我怎么就攤上這事趁怔∈酰” “怎么了?”我有些...
    開封第一講書人閱讀 158,300評論 0 348
  • 文/不壞的土叔 我叫張陵润努,是天一觀的道長关斜。 經(jīng)常有香客問我,道長铺浇,這世上最難降的妖魔是什么痢畜? 我笑而不...
    開封第一講書人閱讀 56,780評論 1 285
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上丁稀,老公的妹妹穿的比我還像新娘繁涂。我一直安慰自己,他們只是感情好二驰,可當我...
    茶點故事閱讀 65,890評論 6 385
  • 文/花漫 我一把揭開白布扔罪。 她就那樣靜靜地躺著,像睡著了一般桶雀。 火紅的嫁衣襯著肌膚如雪矿酵。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 50,084評論 1 291
  • 那天矗积,我揣著相機與錄音全肮,去河邊找鬼。 笑死棘捣,一個胖子當著我的面吹牛辜腺,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播乍恐,決...
    沈念sama閱讀 39,151評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼评疗,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了茵烈?” 一聲冷哼從身側(cè)響起百匆,我...
    開封第一講書人閱讀 37,912評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎呜投,沒想到半個月后加匈,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,355評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡仑荐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,666評論 2 327
  • 正文 我和宋清朗相戀三年雕拼,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片粘招。...
    茶點故事閱讀 38,809評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡啥寇,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出男图,到底是詐尸還是另有隱情示姿,我是刑警寧澤甜橱,帶...
    沈念sama閱讀 34,504評論 4 334
  • 正文 年R本政府宣布逊笆,位于F島的核電站,受9級特大地震影響岂傲,放射性物質(zhì)發(fā)生泄漏难裆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,150評論 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望乃戈。 院中可真熱鬧褂痰,春花似錦、人聲如沸症虑。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,882評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽绊含。三九已至泽台,卻和暖如春皱蹦,著一層夾襖步出監(jiān)牢的瞬間伦泥,已是汗流浹背粟害。 一陣腳步聲響...
    開封第一講書人閱讀 32,121評論 1 267
  • 我被黑心中介騙來泰國打工柿祈, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留屯远,地道東北人苫昌。 一個月前我還...
    沈念sama閱讀 46,628評論 2 362
  • 正文 我出身青樓颤绕,卻偏偏與公主長得像,于是被迫代替她去往敵國和親祟身。 傳聞我的和親對象是個殘疾皇子奥务,可洞房花燭夜當晚...
    茶點故事閱讀 43,724評論 2 351

推薦閱讀更多精彩內(nèi)容