Java mvn spring boot:run不运行';不要启动弹簧

Java mvn spring boot:run不运行';不要启动弹簧,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,答案:我将版本标签从0.0.1-SNAPSHOT更改为1.0.2.RELEASE,并且成功了,请参见下面的答案。 我遵循这一点,并按照说明创建了Example.java。当我运行mvnspring引导时:runspring没有启动,它只是说构建成功。我的理解是Spring应该启动,Tomcat应该提供页面 E:\workspace\SpringBoot>mvn spring-boot:run [INFO] Scanning for projects... [INFO] [INFO] Usi

答案:我将版本标签从0.0.1-SNAPSHOT更改为1.0.2.RELEASE,并且成功了,请参见下面的答案。

我遵循这一点,并按照说明创建了Example.java。当我运行
mvnspring引导时:run
spring没有启动,它只是说构建成功。我的理解是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] ------------------------------------------------------------------------
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位于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>

4.0.0
com.example
我的项目
0.0.1-快照
org.springframework.boot
spring启动程序父级
1.1.0.1构建快照
org.springframework.boot
springbootmaven插件
org.springframework.boot
SpringBootStarterWeb
春季快照
http://repo.spring.io/snapshot
真的
春季里程碑
http://repo.spring.io/milestone
春季快照
http://repo.spring.io/snapshot
春季里程碑
http://repo.spring.io/milestone

您的pom缺少Spring Boot Maven插件:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

org.springframework.boot
springbootmaven插件

我将版本标签从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 boot 1.0.2.0版本进行尝试。“run”mojo在1.1.0快照中发生了更改,您可能遇到了Windows特有的问题(看起来应用程序正在运行,但您没有看到控制台输出)


更新:该错误现在已修复,因此它应该也适用于1.1.0。

我选择了最新版本,并从starter Generator页面中选择了依赖项中的mvc(受够了之后)。一切都很顺利。

我该把这个放在哪里?我把它放在我的pom.xml中,但得到了相同的结果:你把它放在你的pom中,与repositories/pluginRepositories/etc处于同一级别。你能发布你更新的pom吗?我刚刚在上面的原始帖子中更新了我的pom.xml。我刚刚用你更新的pom和上面的示例类创建了一个新的应用程序,它可以与
$mvn一起运行spring boot:run
@MichaelMinella您可以分享如何通过“mvn spring boot:run”命令将jar文件传递给,以便springTry使用spring boot 1.0.2.RELEASE加载和扫描它吗。“run”mojo在1.1.0快照中发生了更改,您可能遇到了Windows特定的问题(看起来应用程序正在运行,但您没有看到控制台输出)。这真是太棒了!春天现在开始了,页面现在正在被服务!所以我刚刚启动了spring boot,但是我应该去哪个URL查看它呢?我去了localhost:8080,我看不到anything@mmcrae默认情况下,它应该是localhost:8080,您能提供您的设置和输出吗?另外,如果您使用spring mvc并为“/”@mmcrae设置了适当的RequestMapping,则需要使用注释或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>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 Boot ::  (v1.1.0.BUILD-SNAPSHOT)