[英]mvn spring-boot:run doesn't start spring
ANSWER: I changed the version tag from 0.0.1-SNAPSHOT to 1.0.2.RELEASE and it worked, see answer below.回答:我将版本标签从 0.0.1-SNAPSHOT 更改为 1.0.2.RELEASE 并且它起作用了,请参阅下面的答案。
I am following this documentation and have created the Example.java as instructed.我正在关注此文档并按照说明创建了 Example.java。 When I run
mvn spring-boot:run
spring doesn't start it just says BUILD SUCCESS.当我运行
mvn spring-boot:run
spring 时,它不会启动它只是说 BUILD SUCCESS。 It's my understanding that Spring should start and Tomcat serving up the page.我的理解是 Spring 应该启动并且 Tomcat 为页面提供服务。
E:\workspace\SpringBoot>mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.1.0.BUILD-SNAPSHOT:run (default-cli) @ myproject >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\workspace\SpringBoot\src\main\resources
[INFO] skip non existing resourceDirectory E:\workspace\SpringBoot\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\workspace\SpringBoot\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ myproject ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.1.0.BUILD-SNAPSHOT:run (default-cli) @ myproject <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.1.0.BUILD-SNAPSHOT:run (default-cli) @ myproject ---
[INFO] Attaching agents: []
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.108 s
[INFO] Finished at: 2014-05-01T14:54:26-05:00
[INFO] Final Memory: 16M/232M
[INFO] ------------------------------------------------------------------------
Here are some details:以下是一些细节:
E:\workspace\SpringBoot>java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
E:\workspace\SpringBoot>mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00)
Maven home: E:\apps\apache-maven-3.2.1\bin\..
Java version: 1.7.0_21, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_21\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Example.java located at E:\\workspace\\SpringBoot\\src\\main\\java: Example.java 位于 E:\\workspace\\SpringBoot\\src\\main\\java:
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
pom.xml located at E:\\workspace\\SpringBoot: pom.xml 位于 E:\\workspace\\SpringBoot:
<?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>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Try it with spring-boot 1.0.2.RELEASE.用 spring-boot 1.0.2.RELEASE 试试吧。 The "run" mojo changed in 1.1.0 snapshots and you might have hit a Windows-specific problem with it (looks like maybe the app is running but you aren't seeing the console output).
“运行”mojo 在 1.1.0 快照中发生了变化,您可能遇到了 Windows 特定的问题(看起来应用程序正在运行,但您没有看到控制台输出)。
Update: that bug is now fixed, so it should work on 1.1.0 as well.更新:该错误现已修复,因此它也应该适用于 1.1.0。
I changed the version tag from 0.0.1-SNAPSHOT to 1.0.2.RELEASE and it worked:我将版本标签从 0.0.1-SNAPSHOT 更改为 1.0.2.RELEASE 并且它起作用了:
<?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>com.example</groupId>
<artifactId>myproject</artifactId>
<version>1.0.2.RELEASE</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Spring now started:春天开始了:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.0.BUILD-SNAPSHOT)
Your pom is missing the Spring Boot Maven Plugin:您的 pom 缺少 Spring Boot Maven 插件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I Went for the latest version and selected mvc in dependencies from starter generater page (after being fed up with this).我去了最新版本,并从启动生成器页面的依赖项中选择了mvc (在厌倦了这个之后)。 All worked like breeze.
一切都像微风一样工作。
I faced with similar problem while refactoring multiple pom.xml at the maven multi-project.我在 maven 多项目中重构多个 pom.xml 时遇到了类似的问题。 Problem began when while 'mvn clean install' Spring didn't start, but he did it before.
当 'mvn clean install' Spring 没有启动时,问题就开始了,但他之前做过。 This problem disappeared when I moved properties-section of maven-surefire-plugin from root-module to the domain-module.
当我将 maven-surefire-plugin 的属性部分从根模块移动到域模块时,这个问题就消失了。 Then I discovered that this dependency was redundant and I removed her.
然后我发现这种依赖是多余的,我删除了她。 This fix looks to be strange but it helped me.
这个修复看起来很奇怪,但它帮助了我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.