简体   繁体   English

如何将Spring应用程序转换为Spring Web应用程序?

[英]How to convert a Spring Application to a Spring Web Application?

I have a Spring Core Application which I would like to convert to a web project. 我有一个Spring Core Application,希望将其转换为Web项目。 I have already implemented all the business logic for my application in a normal Java Project using Eclipse IDE with Maven build. 我已经使用带有Maven构建的Eclipse IDE在普通的Java项目中为我的应用程序实现了所有业务逻辑。

But since I started out with a Core Java Project I do not have the WebContent folder or the Apache Tomcat wrapper. 但是,因为我是从Core Java Project开始的,所以没有WebContent文件夹或Apache Tomcat包装器。 So what would be the best way to convert this project? 那么转换此项目的最佳方法是什么? Should I just change the pom.xml or does Spring have an alternative solution using the SpringBoot which I have already included in the pom.xml? 我应该只更改pom.xml还是Spring使用已经包含在pom.xml中的SpringBoot替代解决方案? (As you can tell I am new to Spring framework) (如您所知,我是Spring框架的新手)

Here is my pom.xml 这是我的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>

You can configure the directories required for Web under project facets . 您可以在project facets下配置Web所需的目录。 You can do that by, 你可以这样做

Right click on the project properties. 右键单击项目属性。 Select “Project Facets“, and click “convert to faceted form…” 选择“项目构面”,然后单击“转换为构面形式…”

A nice tutorial here by mkyong have a look at it 一个很好的教程在这里通过mkyong看看它

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

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