编程语言
首页 > 编程语言> > java – 如何在Eclipse中创建一个正确配置了Run Configuration的Spring Boot Starter项目?

java – 如何在Eclipse中创建一个正确配置了Run Configuration的Spring Boot Starter项目?

作者:互联网

我按照Spring Boot Support in Spring Tool Suite 3.6.4中的说明进行操作,最后得到了一个有几个问题的Eclipse项目.第一个问题是,当我右键单击包含“main”条目方法的类并选择“Run As”选项时,我得到的唯一条目是后备“Run Configurations …”方法.我既没有选择将它作为“Spring Boot App”或“Java Application”运行.

我的问题是如何根据该站点中的说明创建项目或我该怎么做以获得该运行方式选项?

除上述信息外,我还应补充以下内容:

>我正在使用Eclipse 4.4.2(Luna SR2)和STS 3.7.1
>我在Windows和Linux上都试过它(Fedora with OpenJDK)
>使用Java 8(Sun Hotspot 64位1.8.0_65)
>当最初创建pom.xml时,它显然有错误,因为m2e想要的配置丢失,我需要添加以下内容:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <versionRange>[3.1,)</versionRange>
                                <goals>
                                    <goal>compile</goal>
                                    <goal>testCompile</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <ignore />
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

>看起来Eclise项目也没有为Java应用程序正确配置. Java src树没有配置.下面是.project文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>demo</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
        </natures>
</projectDescription>

>我可以按照How to run Spring Boot web application in Eclipse itself?手动运行应用程序(通过执行[Project] – > Run As – > Maven Build … – >目标:spring-boot:run

解决方法:

要在sts中创建一个新的spring-boot项目,只需单击新的spring-starter项目,即可为您创建项目.
New-> Project-> Spring-> Spring启动项目

您将在向导中选择“Web”复选框以选择Web应用程序
这将创建一个这样的应用程序类

@SpringBootApplication
public class DemoApplication {

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

我的自动生成POM

<?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>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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


</project>

标签:java,eclipse,maven,spring-tool-suite
来源: https://codeday.me/bug/20190519/1136383.html