今天把前天的sprinngboot项目和另外一个同事的springboot项目整合,结果整合完毕启动报错。网上的方法都试过了,都没有解决这个问题。后来我就把pom文件中的springboot版本由2.1.1.RELEASE换回整合前的1.5.8.RELEASE,再启动就正常起来了。所以降低到2.0一下的版本是一种解决方案。
报错信息如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
2019-01-16 16:34:52.215 [restartedMain] INFO telemetry.server.Application - Starting Application on zhanglifeng with PID 27308 (D:\gccp_WorkSpace\TelemetryServer\target\classes started by Shinelon in D:\gccp_WorkSpace\TelemetryServer)
2019-01-16 16:34:52.219 [restartedMain] INFO telemetry.server.Application - No active profile set, falling back to default profiles: default
2019-01-16 16:34:52.274 [restartedMain] INFO o.s.b.d.env.DevToolsPropertyDefaultsPostProcessor - Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-01-16 16:34:52.274 [restartedMain] INFO o.s.b.d.env.DevToolsPropertyDefaultsPostProcessor - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-01-16 16:34:53.201 [restartedMain] WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[telemetry.server]' package. Please check your configuration.
2019-01-16 16:34:53.436 [restartedMain] INFO o.s.d.r.config.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-16 16:34:53.514 [restartedMain] INFO o.s.d.r.config.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 70ms. Found 2 repository interfaces.
2019-01-16 16:34:53.943 [restartedMain] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ba7f6885] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-16 16:34:53.977 [restartedMain] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2019-01-16 16:34:53.989 [restartedMain] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-16 16:34:53.993 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at telemetry.server.Application.main(Application.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: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:206)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
... 13 common frames omitted
我的springboot项目结构如下:
Application.java:
package telemetry.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 配置除去了自动配置数据源的类-DataSourceAutoConfiguration,因为
* 这个注解会把sping的配置的数据源全部都自动注入,不会默认注入一个,当使用其他数据源时再调用另外的数据源。
* @author Administrator
*
*/
@Controller
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class Application /*extends SpringBootServletInitializer*/{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
/*@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}*/
@RequestMapping("/")
@ResponseBody
public String home() {
return "Minecraft Telemtry start success !";
}
}
对应pom.xml配置文件:
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jdcloud.springhbase</groupId>
<artifactId>TelemetryServer</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- 增加父pom ,spring-boot-starter-parent包含了大量配置好的依赖管理,他是个特殊的starter,它提供了有用的maven默认设置 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- Spring默认使用jdk1.6,如果你想使用jdk1.8,你需要在pom.xml的属性里面添加java.version,如下: -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>7.0.72</tomcat.version>
<java.version>1.8</java.version>
<spring.boot.version>1.5.8.RELEASE</spring.boot.version>
</properties>
<!-- Spring通过添加spring-boot-starter-*这样的依赖就能支持具体的某个功能。 -->
<!-- 我们这个示例最终是要实现web功能,所以添加的是这个依赖。 -->
<dependencies>
<dependency>
<!-- 指定为Web应用,并启动一个内嵌的Servlet容器(默认是Tomcat)用于处理HTTP请求 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- springboot单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- lombok插件,方便model对象的处理,不用写get,set方法。 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<!-- Mybatis的jar包 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 添加mongodb依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- 设置为热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。 相当于compile,但是打包阶段做了exclude操作-->
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- 打包后的jar包名称 -->
<finalName>TelemetryServer</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<!-- 必须要的SpringBoot继承的maven插件,缺少了无法打包jar。 -->
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<!-- 在我们开发过程中,我们需要经常修改,为了避免重复启动项目,我们可以启用热部署。 Spring-Loaded项目提供了强大的热部署功能,
添加/删除/修改 方法/字段/接口/枚举 等代码的时候都可以热部署,速度很快,很方便。 想在Spring Boot中使用该功能非常简单 ,就是在spring-boot-maven-plugin插件下面添加依赖: -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>