복붙노트

[SPRING] Spring + Maven 종료 코드 1로 Java를 실행할 수 없습니다.

SPRING

Spring + Maven 종료 코드 1로 Java를 실행할 수 없습니다.

Spring / Maven을 처음 사용하고 있으며이 튜토리얼을 따릅니다. Spring MVC로 웹 컨텐츠 제공.

mvn spring-boot : run을 실행할 때마다 다음 오류가 발생합니다.

클래스 경로를 추가하고 mvn install clean spring-boot : run을 실행하려고했지만 비슷한 상황에서 사람들이 스택 오버 플로우에 대해 제안한 많은 다른 작업을 수행했지만 8 시간 이상 사용하지 않았습니다.

내 주요 클래스 Application.java는 다음과 같습니다.

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) throws Exception{
        SpringApplication.run(Application.class, args);
    }
}

내 GreeetingController.java 클래스는 다음과 같습니다.

package hello;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {

    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }

}

내 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.springframework</groupId>
    <artifactId>gs-serving-web-content</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</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-starter-web</artifactId>
            <!-- Exclusions to allow SpringBoot execute on HCP -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-el</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <properties>
        <java.version>1.8</java.version>
        <!-- The main class to start by executing java -jar -->


    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                                    <mainClass>hello.Application</mainClass>

        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            </manifest>
        </archive>
    </configuration>
            </plugin>
        </plugins>
    </build>

</project>

내 HTML 템플릿은 다음과 같습니다.

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>

프로젝트의 구조는

src/main/java/hello/pom.xml
src/main/java/hello/Application.java
src/main/java/hello/GreetingController.java
src/main/resources/templates/greeting.html

해결법

  1. ==============================

    1.mvn clean spring-boot : run 작동하도록 다음과 같이 변경했습니다.

    mvn clean spring-boot : run 작동하도록 다음과 같이 변경했습니다.

    디렉토리 계층 :

    .
    ├── pom.xml
    └── src
        └── main
            ├── java
            │   └── hello
            │       ├── Application.java
            │       └── GreetingController.java
            └── resources
                └── templates
                    └── greeting.html
    

    부분 주석 처리 :

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- Exclusions to allow SpringBoot execute on HCP -->
            <!--<exclusions>-->
                <!--<exclusion>-->
                    <!--<groupId>org.springframework.boot</groupId>-->
                    <!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
                <!--</exclusion>-->
                <!--<exclusion>-->
                    <!--<groupId>org.apache.tomcat.embed</groupId>-->
                    <!--<artifactId>tomcat-embed-el</artifactId>-->
                <!--</exclusion>-->
                <!--<exclusion>-->
                    <!--<artifactId>logback-classic</artifactId>-->
                    <!--<groupId>ch.qos.logback</groupId>-->
                <!--</exclusion>-->
            <!--</exclusions>-->
        </dependency>
    

    그러한 의존성을 배제하려는 것 같습니다. 내장 Tomcat을 제외하면 mvn clean spring-boot : run이 성공적으로 종료되지만 응용 프로그램을 배포 할 컨테이너가 없기 때문에 이것이 올바르게 작동한다고 생각합니다. 어쨌든 시도해보고 요구 사항에 따라 변경할 수 있습니다.

  2. ==============================

    2.때로는 포트가 이미 사용 중일 수 있으므로 응용 프로그램을 실행하기 전에 모든 Java 프로세스를 종료해야합니다.

    때로는 포트가 이미 사용 중일 수 있으므로 응용 프로그램을 실행하기 전에 모든 Java 프로세스를 종료해야합니다.

  3. ==============================

    3.나는 당신과 같은 오류를 겪었고 마침내 나는 "spring-boot-starter-parent"와 "spring-boot-autoconfigure"사이의 잘못된 협력 버전에 의해 발견되었으며, 동일한 버전으로 확인했습니다. 또한 그들의 버전이 최신인지 확인하십시오.

    나는 당신과 같은 오류를 겪었고 마침내 나는 "spring-boot-starter-parent"와 "spring-boot-autoconfigure"사이의 잘못된 협력 버전에 의해 발견되었으며, 동일한 버전으로 확인했습니다. 또한 그들의 버전이 최신인지 확인하십시오.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
    
  4. ==============================

    4.제 경우에는 "devtools"의존성을 삭제합니다.

    제 경우에는 "devtools"의존성을 삭제합니다.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
    

    그리고 작동합니다!

  5. from https://stackoverflow.com/questions/43157515/could-not-exec-java-with-springmaven-exit-code-1 by cc-by-sa and MIT license