首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以将Maven项目转换为SpringBoot吗

我可以将Maven项目转换为SpringBoot吗
EN

Stack Overflow用户
提问于 2015-03-31 12:28:51
回答 5查看 35.6K关注 0票数 10

我在Eclipse中有一个Maven项目,现在我需要添加数据库连接。我的教科书在Maven中做了所有的json教程。现在在关于JDBC的这一章中,他们使用了SpringBoot。

我可以将项目转换为SpringBoot吗?或者启动一个SpringBoot并导入我之前的maven类。

EN

回答 5

Stack Overflow用户

发布于 2015-03-31 16:20:19

Here is described如何在SpringBoot项目中使用maven。

您需要修改现有的项目以添加类似以下内容的内容,以使其成为SpringBoot项目:

代码语言:javascript
复制
<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.2.RELEASE</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
票数 13
EN

Stack Overflow用户

发布于 2017-10-31 17:32:58

将Maven项目转换为SpringBoot

  • Ist选项:使用父POM

的Spring Boot

在pom.xml文件中添加以下依赖项**:-

1.)继承starter parent(spring-boot-starter-parent):-boot- starter -parent是一个特殊的starter,它提供了有用的Maven默认值。

2.) spring-boot-starter-web :-使用Spring MVC构建web应用程序的入门程序,包括RESTful应用程序。使用Tomcat作为默认的嵌入式容器。

3.) Maven包含一个可以将项目打包为可执行jar的spring-boot-maven-plugin:-插件。

这是pom.xml:

  • 2nd选项:在没有父POM

的情况下使用Spring Boot

并不是每个人都喜欢继承spring-boot-starter-parent POM。您可能需要使用自己的公司标准父组件,或者您可能更喜欢显式声明所有的Maven配置。

如果您不想使用spring-boot-starter-parent,,您仍然可以通过使用scope=import dependency保留依赖项管理(而不是插件管理)的好处,如下所示:

< dependency> < !--从Spring Boot导入依赖管理-->

< groupId>org.springframework.boot< /groupId>

< artifactId>spring-boot-dependencies< /artifactId>

<版本>2.0.0.BUILD-SNAPSHOT< /version> < type>pom< /type>

< scope>import< /scope> < /dependency>

有关更多详细信息,请参阅Spring Boot Docs:- https://docs.spring.io/spring-boot/docs/1.4.7.RELEASE/reference/htmlsingle/#getting-started-maven-installation

票数 6
EN

Stack Overflow用户

发布于 2018-08-13 02:09:46

1)在Pom.xml文件中添加Spring boot starter Parent和Web

2)在类中添加@SpringBootApplication

3)在main方法中添加SpringApplication.run(App.class,args);。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29360631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档