最近在搭建一个springboot(springboot版本是1.5.1.RELEASE)的web项目时(编译类型是gradle),总是无法正常启动,网上各种找解决办法,都没能解决问题。下面简单给出build.gradle的配置。
先给出错误提示信息:
2019-10-21 17:55:13.636 INFO 7180 --- [ main] c.h.l.s.demo.SpringBootDemoApplication : Started SpringBootDemoApplication in 10.394 seconds (JVM running for 10.922)
2019-10-21 17:55:13.639 INFO 7180 --- [ Thread-5] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4386f16: startup date [Mon Oct 21 17:55:03 CST 2019]; root of context hierarchy
2019-10-21 17:55:13.643 INFO 7180 --- [ Thread-5] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
项目的build.gradle配置如下:
buildscript{
ext{
sprintBootVersion = '1.5.1.RELEASE'
}
repositories{
maven {url "http://maven.aliyun.com/nexus/content/groups/public/"}
}
dependencies{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${sprintBootVersion}")
}
}
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
mainClassName = 'com.xxx.xxx.demo.SpringBootDemoApplication'
group = 'com.hezs.learn.springboot'
version = '0.0.1-SNAPSHOT'
jar{
baseName = 'springbootdemo'
version = '1.0.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
runtime "mysql:mysql-connector-java:6.0.3"
compile "org.flywaydb:flyway-core:3.2.1"
compile 'org.projectlombok:lombok:1.16.12'
compile "org.springframework.boot:spring-boot-starter-parent:${sprintBootVersion}"
compile "org.springframework.boot:spring-boot-starter-web:${sprintBootVersion}"
compile "org.springframework.boot:spring-boot-starter-data-jpa:${sprintBootVersion}"
compile "org.springframework.boot:spring-boot-starter-tomcat:${sprintBootVersion}"
testCompile "org.springframework.boot:spring-boot-starter-test:${sprintBootVersion}"
}
网上给出了各种解决办法,都试过之后,无解
最后找到一个提示性的答案,Tomcat的依赖方式,在maven的pom.xml中是provided,对应的gradle是compileOnly,仅仅需要修改一下依赖方法就OK了
compile "org.springframework.boot:spring-boot-starter-tomcat:${sprintBootVersion}"
–>
compileOnly "org.springframework.boot:spring-boot-starter-tomcat:${sprintBootVersion}"
问题得到解决。