升级gradle和Spring启动版本后,Spring启动kafka应用不作为控制台应用启动



升级详情。弹簧启动:2.2.7-RELEASE到2.4.6Gradle: 4.10.3到6.9.2

build.gradle

plugins{
id 'org.springframework.boot' version '2.4.6'
id 'io.spring.dependency-management' version '1.0.11.RELESE'
id 'java'
}
sourceCompatibility ='1.8'
dependency-management{
import {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.4"
}
}
dependencies{
implmentation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implmentation 'org.springframework.boot:spring-boot-starter-web'
implmentation 'org.springframework.kafka:spring-kafka'
implmentation 'org.projectlombok.lombok'
testImplmentation 'org.springframework.boot:spring-boot-starter-test'
implmentation 'org.springframework.cloud:spring-cloud-starter-config'
implmentation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
compile 'org.springframework.boot:spring-boot-starter-webflux'
implmentation 'org.springframework.boot:spring-boot-starter-data-jpa'
compile(group: 'org.springframework.boot', name: 'spring-boot-configuaration-processor')
compile(group: 'com.microsoft.sqlserver', name: 'mssql-jdbc' version: '8.3.1.jre8-preview')
runtimeOnly 'com.microsoft.sqlserver:mysql-jdbc'
implmentation 'io.springfox:springfox-swagger2:2.9.2'
implmentation 'io.springfox:springfox-swagger-ui:2.9.2'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.projectreactor:reactor-spring'
implmentation 'io.micrometer:micrometer-registry-prometheus'
implmentation 'javax.mail:mail:1.4'
testImplmentation 'junit:junit'
annotationProcessor 'org.projectlombok:lombok'

}
wrapper{
distribuationUrl = "https://services.gradle.org/distributions/gradle-6.9.2-bin"
}

主类:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@EnableKafka
@EnableScheduling
public class SpringBootMainClassApplication {
public static void main(String[] args) {

SpringApplication.run(SpringBootMainClassApplication.class, args);
}
}

application.properties

server.port=8080

错误:" ApplicationContextException: Unable to start ServletWebServerApplicationContext由于缺少ServletWebServerFactory bean " .

输入图片描述

将以下属性添加到application.properties.

后代码运行正常
spring.main.web-application-type=none

应用程序作为控制台应用程序运行良好,无需更改spring.main。web-application-type=none的属性与旧版本的spring boot 2.2.7-RELEASE,你能帮我们运行应用程序不添加新的属性吗?

这是正常工作,似乎你的gradle有很多错误

请使用这个gradle,永远爱你的代码美丽,它可以像一幅画:)

plugins {
id "io.spring.dependency-management" version "1.0.11.RELEASE"
id "org.springframework.boot" version "2.4.6"
id "java"
}
sourceCompatibility ='1.8'
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.4"
}
}
dependencies
{
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jdbc'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.kafka', name: 'spring-kafka'

implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'javax.mail:mail:1.4'

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
compileOnly group: 'org.springframework.boot', name: 'spring-boot-configuaration-processor'
compileOnly group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '8.3.1.jre8-preview'

compileOnly 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.springframework.boot:spring-boot-starter-actuator'
compileOnly 'org.projectreactor:reactor-spring'

runtimeOnly 'com.microsoft.sqlserver:mysql-jdbc'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'junit:junit'

annotationProcessor 'org.projectlombok:lombok'
}

相关内容

  • 没有找到相关文章

最新更新