Eclipse创建web项目没有webcontent:在Eclipse中设置SpringBootWeb项目

关于Eclipse创建web项目没有webcontent的问题,在springboot project中经常遇到, 我是 Spring Web 开发的新手。基本上,我需要知道如何在 Eclipse IDE 中运行 Spring 项目。这里是我到目前为止已经完成的详细步骤,用 pics / code 来支持我的问题。

我是 Spring Web 开发的新手。基本上,我需要知道如何在 Eclipse IDE 中运行 Spring 项目。这里是我到目前为止已经完成的详细步骤,用 pics / code 来支持我的问题。

我访问了 Spring Initializr 网站并下载了一个 maven 项目文件夹。我输入了以下信息:项目:Maven 项目语言:Java Spring Boot:3.0.0 (SNAPSHOT) ProjectMetadata-Group:com.example ProjectMetadata-Artifact:demo10 ProjectMetadata-Name:SpringTest 依赖项:
Spring Web-构建 web,包括 RE

我将下载的文件导入 Eclipse 作为现有的 Maven 项目。(Eclipse 版本 2021-12(4.22.0)

创建的类是由 spring initializer 创建的

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);
    }
}

我创建了以下控制器类

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";
    }
}
Here is the project file structure in Eclipse

这里是 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>

所以以下是我的两个问题:a.从这一点我如何在 Tomcat 服务器上运行项目。我已经安装了两个版本的 Tomcat。b.我应该使用什么 url 来调用 api?

谢谢

0

正如你所说,使用 Apache Tomcat 作为默认的嵌入式容器。当你在主类中识别 @ SpringBootApplication 注释时,你可以运行你的项目

Spring Boot 使用 localhost::8080 作为默认值。此外,您可以使用应用程序属性文件(例如“server.port = 9999”)更改它,您的 URL 将是 localhost::9999

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(79)
Python好书推荐:任何人都可以为Ruby初学者推荐一本好书吗
上一篇
Php源码加密授权系统:Votifier PHP加密
下一篇

相关推荐

  • 在Docker中使用SpringBootJava生成ApachePOI xlsx文件

    我有使用 iTextPdf 生成 PDF 的应用程序,现在我已经添加了一些 Apache POI 来在相同的数据上生成 Excel 文件。前面是带有 jQuery 的 JS,后端是带有 Spring Boot 的 Java 11 (openJDK),Apache POI 5.0。问题是在 IDE 中运行时一切正常。生成文件并下载没有问题。当我运行 apps docker 容器时出现问题。如果我尝试生成 Excel 文件,我得到错误…

    2022-11-20 08:21:18
    0 76 22
  • 在Docker中使用SpringBootJava生成ApachePOI xlsx文件

    我有使用 iTextPdf 生成 PDF 的应用程序,现在我已经添加了一些 Apache POI 来在相同的数据上生成 Excel 文件。前面是带有 jQuery 的 JS,后端是带有 Spring Boot 的 Java 11 (openJDK),Apache POI 5.0。问题是在 IDE 中运行时一切正常。生成文件并下载没有问题。当我运行 apps docker 容器时出现问题。如果我尝试生成 Excel 文件,我得到错误…

    2022-11-11 15:11:47
    0 55 70
  • cmd 执行pythonecho 'Hello World' > Hello_World.txt

    在 Windows 上,可以使用 cmd 执行 python,具体步骤如下:确保安装了 Python,并将其路径添加到系统环境变量中。…

    2023-05-23 15:39:55
    0 31 46
  • vscode怎么运行python文件:如何使用VSCode运行Python文件

    打开vscode,点击文件->打开文件,选择你要运行的python文件;在vscode编辑器中,可以看到你的python文件;…

    2023-06-17 02:36:32
    0 75 22
  • scratch与python区别开发者的不同选择

    Scratch和Python之间的主要区别在于它们的语言类型。Scratch是一种基于图形的编程语言,它使用可视化拖放模块来构建程序,而Python是一种文本型编程语言,它使用编写代码的文本语法来构建程序。…

    2023-04-18 06:12:58
    0 10 78
  • pythoncharm安装教程:如何使用PythonCharm安装和配置

    访问官网,https://www..com/pycharm//,下载最新版本的安装包。双击下载的安装包,开始安装,在安装过程中,根据提示选择安装路径、安装组件等,直到安装完成。…

    2024-03-24 10:13:21
    0 62 59
  • php substr函数 Unlocking the Potential of Your Strings

    示例示例substr() 函数返回字符串的一部分。语法:…

    2023-07-27 07:03:10
    0 16 56
  • gcc编译静态库:```shellar rcs libhello.a hello.o```最终会生成一个名为libhello.a

    静态库是指在程序运行时,将一些函数和数据封装到一个文件中,并在程序运行时将其加载到内存中,以便程序调用。使用gcc编译静态库的步骤如下:…

    2023-03-31 11:07:28
    0 18 59

发表评论

登录 后才能评论

评论列表(41条)