【问题标题】:How to convert a Spring Application to a Spring Web Application?如何将 Spring 应用程序转换为 Spring Web 应用程序?
【发布时间】:2023-03-15 02:30:01
【问题描述】:

我有一个 Spring Core 应用程序,我想将它转换为一个 Web 项目。我已经使用带有 Maven 构建的 Eclipse IDE 在普通 Java 项目中为我的应用程序实现了所有业务逻辑。

但由于我开始使用核心 Java 项目,因此我没有 WebContent 文件夹或 Apache Tomcat 包装器。那么转换这个项目的最佳方法是什么?我应该只更改 pom.xml 还是 Spring 是否有使用我已经包含在 pom.xml 中的 SpringBoot 的替代解决方案? (如您所知,我是 Spring 框架的新手)

这是我的 pom.xml

<?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>org.springframework</groupId>
<artifactId>gs-serving-web-content</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.2.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-pool2</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

</project>

【问题讨论】:

    标签: java eclipse spring maven spring-mvc


    【解决方案1】:

    您可以在project facets 下配置Web 所需的目录。你可以这样做,

    右键单击项目属性。选择“Project Facets”,然后 点击“转换为多面形式...”

    mkyong 的一个很好的教程here 看看它

    【讨论】:

    • 但这不会反映我对 pom.xml 所做的更改吗?如果其他人从 git 中拉出我的项目怎么办?
    • 它与您的pom.xml 无关,以确保您在其中所做的更改。您必须为该项目执行 maven--install 并检查您的库文件夹中是否有新添加的 jars
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多