问题
I followed the instructions in Spring Boot Support in Spring Tool Suite 3.6.4 and ended up with an Eclipse project which has several issues. The number one issue is that when I right-click on the class containing the "main" entry method and select the "Run As" option, the only entry I get is the fallback "Run Configurations..." method. I neither get the option to run it as a "Spring Boot App" or as a "Java Application".
My question is how do I create the project or what do I do after it's created following the instructions in that site to get that Run As option?
In addition to the above information, I should add the following:
- I'm using Eclipse 4.4.2 (Luna SR2) and STS 3.7.1
- I've tried it on both Windows and Linux (Fedora with OpenJDK)
- Used Java 8 (Sun Hotspot 64-bit 1.8.0_65)
When the pom.xml initially gets created, it has an error apparently due to a missing config the m2e wants for which I needed to add the following:
<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>
It doesn't look like the Eclise project is properly configured for a Java application either. There's no configuration for a Java src tree. Below is the .project file:
<?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>
- I can manually run the app as per How to run Spring Boot web application in Eclipse itself? (by executing [Project] --> Run As --> Maven Build... --> Goal: spring-boot:run
回答1:
You'll need to install the Spring Tool Suite plug-in for Eclipse. Then you'll see the "Spring Boot App" run configuration (and other STS features).
回答2:
To create a new spring-boot project in sts just click new spring-starter project, that will create the project for you. New->Project->Spring->Spring starter project
You'll run throught the wizard select 'Web' checkbox to have the web app selected this will create an application class like this
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My auto generated 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>
回答3:
After creating a Spring Boot application via the Spring Starter project via the menu need to do additional steps: Go into project properties and enable the Java facet. Then, right-click project and Maven > Update Project.
来源:https://stackoverflow.com/questions/33484363/how-do-i-create-a-spring-boot-starter-project-in-eclipse-that-is-properly-config