How to create a Spring bootstrap project in Eclipse that is properly configured using a startup configuration?

I followed the instructions in Spring. Download support in Spring Tool Suite 3.6.4 and ended with the Eclipse project, which has several problems. Problem number one is that when I right-click on the class that contains the "main" method and select the "Run as" option, the only record I get is the backup method "Run configuration ...". I do not get the opportunity to run it as a "Spring Boot App" or as a "Java Application".

My question is: how do I create a project or what to do after creating it in accordance with the instructions on this site to get this "Run As" option?

In addition to the information above, I must add the following:

  • I am using Eclipse 4.4.2 (Luna SR2) and STS 3.7.1
  • I tried this on both Windows and Linux (Fedora with OpenJDK)
  • Using Java 8 (Sun Hotspot 64-bit 1.8.0_65)
  • When pom.xml is initially created, it has an error, apparently due to the missing configuration that m2e requires, 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 does not look like the Eclise project is also configured for a Java application. There is no configuration for the Java src tree. The following 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 start the application in accordance with How to run Spring Boot web application in Eclipse itself? (by executing [Project] → Run As - → Maven Build ... → Target: spring-boot: run
+5
source share
3 answers

To create a new spring-boot project in sts, simply click on the new spring-starter project, which will create the project for you. New-> Project → Spring → Spring starter project

You run the wizard, select the "Web" checkbox to select a web application this will create an application class similar to 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
source

You need to install Spring Tool Suite plugin for Eclipse . Then you will see the "Spring Boot App" startup configuration (and other STS features).

+2
source

After creating the Spring Boot application through the Spring Starter project, you need to perform additional actions through the menu: go to the project properties and enable the Java facet. Then right-click the project and Maven> Update Project.

0
source

Source: https://habr.com/ru/post/1235036/


All Articles