簡體   English   中英

Gradle 無法啟動 Spring 啟動

[英]Gradle cannot start Spring Boot

我正在嘗試將 RESTful web 服務添加到現有的 Java 應用程序中。 My technology stack is Spring( Web services & Boot), Gradle build, and Tomcat 10 Web server, finally all on Windows 10.

為了:

1)這是我的 Gradle:

   plugins {
        id 'org.springframework.boot' version '2.6.2'
        id 'java'
    }
    sourceCompatibility = '1.8'
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
    
    if (!hasProperty('mainClass')) {
        ext.mainClass = 'oaisclientnew.Main'
    }
    
    repositories {
        mavenCentral()
}
    
    task fatJarLib(type: Jar) {
        manifest {
            
        }
        
        baseName = 'oais_restful_server'
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with jar
    }
    
    
    dependencies {
    
        testCompile group: 'junit', name: 'junit', version: '4.10'
        //implementation name: 'libs/oais_if_prototype_lib.jar'
        compile fileTree(dir: 'libs', include: '*.jar') 
        // https://mvnrepository.com/artifact/org.springframework.ws/spring-ws
        implementation 'org.springframework.ws:spring-ws:3.1.1'
        // https://mvnrepository.com/artifact/org.springframework/spring-web
        implementation 'org.springframework:spring-web:5.3.14'
        // https://mvnrepository.com/artifact/org.springframework/spring-core
        implementation 'org.springframework:spring-core:5.3.14'
        // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
        implementation 'org.springframework.boot:spring-boot-starter-web:2.6.2'
    }
  1. 好像和8080端口上的另一個應用程序有沖突,所以我把Tomcat 10改為監聽9090端口。

當我輸入: http://localhost:9090/時,會顯示Tomcat的歡迎頁面。

2)

下面是Main & SpringApplication.run (相關片段沒有導入):

   @SpringBootApplication
    @Configuration
    @EnableAutoConfiguration
    public class Main {
    
        public static void main(String[] args) {
            SpringApplication.run(Main.class, args);
        }
    
        @Bean
        public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
            return args -> {
    
                System.out.println("Spring boot!");
    
                String[] beanNames = ctx.getBeanDefinitionNames();
                Arrays.sort(beanNames);
                for (String beanName : beanNames) {
                    System.out.println(beanName);
                }
    
            };
    
        }
    
    }

3)Controller:(僅相關代碼)

@RestController
public class PDS4FrontCrontroller {

    //@RequestMapping(value="/pds4_injest")
        @GetMapping(value="/pds4_injest")
    public PDS4MetaData greeting() {
        return new PDS4MetaData("C:\\Users\\anaim\\Desktop\\MIST\\for_ary\\A0087_0014_597774923_597783273_181207004231_eu.xml", "https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1B10.xsd");
    }
}

我能夠使用gradle clean build項目。 However, I cant deploy the project and/or Spring Boot when I issue the command gradle bootRun , it taking Gradle over 20 hours to start Spring Boot: See below:

<

==========---> 80% EXECUTING [3m 7s]onfigure.web.ServerProperties
servletWebServerFactoryCustomizer
simpleControllerHandlerAdapter
<==========---> 80% EXECUTING [20h 33m 25s]nfigure.info.ProjectInfoProperties
<==========---> 80% EXECUTING [20h 33m 54s]oconfigure.jackson.JacksonProperties
spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties
Terminate batch job (Y/N)? NG [20h 33m 26s]figure.web.servlet.WebMvcProperties
spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
spring.sql.init-org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties
spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties
spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties
spring.web-org.springframework.boot.autoconfigure.web.WebProperties
standardJacksonObjectMapperBuilderCustomizer
<==========---> 80% EXECUTING [11s]
taskExecutorBuilder
taskSchedulerBuilder
<==========---> 80% EXECUTING [3m 4s]
tomcatServletWebServerFactory
<==========---> 80% EXECUTING [14s]izer
tomcatWebServerFactoryCustomizer
viewControllerHandlerMapping
viewNameTranslator
viewResolver
webServerFactoryCustomizerBeanPostProcessor
websocketServletWebServerCustomizer
welcomePageHandlerMapping
<==========---> 80% EXECUTING [10s]
> :bootRun

有什么建議么?

謝謝

Try to downgrade to Tomcat 9 since Tomcat 10 and Spring 5 are not compatible due to the package being named differently, jakarata replaced javax packages.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM