微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法用Spring Maven退出代码1来执行java

我是Spring / Maven的新手,我正在学习本教程:
Serving Web Content with Spring MVC.

每次我运行mvn spring-boot:run,我都会收到此错误

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project gs-serving-web-content: Could not exec java: Application finished with exit code: 1 ->

我试图添加classpath,试图运行mvn install clean spring-boot:run,做了很多其他的事情,人们在类似的情况下建议stackoverflow,花了这么多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文件

spring-boot-starter-parentspring-boot-starter-thymeleafspring-boot-starter-webspring-boot-starter-tomcatbedbed-elfiguration>
                                    sspath>truesspath>
            figuration>
            

这是我的HTML模板:

Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

项目的结构是

src/main/java/hello/pom.xml
src/main/java/hello/Application.java
src/main/java/hello/GreetingController.java
src/main/resources/templates/greeting.html
最佳答案
我做了以下更改,使mvn clean spring-boot:run work:

>将pom.xml移动到根目录,这使目录层次结构为:

目录层次:

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

>在以下部分中注释掉了扩展:

注释掉部分:

spring-boot-starter-webspring-boot-starter-tomcatbedbed-el

您似乎打算排除这些依赖项. mvn clean spring-boot:如果排除了嵌入式tomcat,run将成功退出,但我认为这是正确的行为,因为没有容器来部署应用程序.无论如何,您可以尝试并根据您的要求进行更改.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐