简体   繁体   English

Spring Boot Web 项目设置Eclipse

[英]Spring Boot Web project set up in Eclipse

I am new to Spring Web development.我是 Spring Web 开发的新手。 Basically, I need to know how to run the Spring project in Eclipse IDE. Here are the detailed steps I have perfoormed so far, with pics/code to support my question.基本上,我需要知道如何在 Eclipse IDE 中运行 Spring 项目。以下是我到目前为止执行的详细步骤,并附有图片/代码来支持我的问题。

  1. I visited Spring Initializr site and downloaded a maven project folder.我访问了 Spring Initializr 站点并下载了一个 maven 项目文件夹。 I endered the following information: Project: Maven Project Language: Java Spring Boot: 3.0.0 (SNAPSHOT) ProjectMetadata - Group: com.example ProjectMetadata - Artifact: demo10 ProjectMetadata - Name: SpringTest Dependencies:我输入了以下信息: 项目:Maven 项目语言:Java Spring 启动:3.0.0 (SNAPSHOT) ProjectMetadata - 组:com.example ProjectMetadata - 工件:demo10 ProjectMetadata - 名称:SpringTest 依赖项:
    Spring Web - Build web, including RESTful, applications using Spring MVC. Spring Web - 构建 web,包括 RESTful,使用 Spring MVC 的应用程序。 Uses Apache Tomcat as the default embedded container.使用 Apache Tomcat 作为默认的嵌入式容器。

  2. I imported the downloaded file into Eclipse as Existing Maven Project.我将下载的文件作为现有的 Maven 项目导入到 Eclipse 中。 (Eclipse Version 2021-12(4.22.0) (Eclipse 版本 2021-12(4.22.0)

  3. Created the following class was created by spring initializer创建了以下 class 由 spring 初始值设定项创建

package com.example.demo10;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringTestApplication {

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

}
  1. I created the following controller class我创建了以下 controller class
package com.example.demo10;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public  class MyController {
    @GetMapping("/welcome")
    public String getWelcome() {
        System.out.println("test");
        return "we are fome";
    }
}
  1. Here is the project file structure in Eclipse这是Eclipse中的项目文件结构

  2. Here is the pom file这是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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo10</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringTest</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</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>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

</project>

So following are my two questions: a.所以以下是我的两个问题:a。 From this point how do I run the project on Tomcat server.从这一点来看,我如何在 Tomcat 服务器上运行项目。 I already have two versions of Tomcat installed.我已经安装了两个版本的 Tomcat。 b. b. What is the url I should use to call the api?我应该使用什么 url 来呼叫 api?

Thanks谢谢

as you said, Uses Apache Tomcat as the default embedded container.如您所说,使用 Apache Tomcat 作为默认的嵌入式容器。 you can run your project when you identify @SpringBootApplication annotation in your main class当您在主 class 中识别 @SpringBootApplication 注释时,您可以运行您的项目

Spring boot use url that is localhost::8080 as a default.Also, you can change it using application properties files for example "server.port = 9999" and your url will be localhost::9999 Spring 引导使用 url,默认为 localhost::8080。此外,您可以使用应用程序属性文件更改它,例如“server.port = 9999”,您的 url 将是 localhost::9999

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM