我在Eclipse中有一个Maven项目,现在我需要添加数据库连接。我的教科书在Maven中做了所有的json教程。现在在关于JDBC的这一章中,他们使用了SpringBoot。
我可以将项目转换为SpringBoot吗?或者启动一个SpringBoot并导入我之前的maven类。
发布于 2015-03-31 16:20:19
Here is described如何在SpringBoot项目中使用maven。
您需要修改现有的项目以添加类似以下内容的内容,以使其成为SpringBoot项目:
<!-- 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>发布于 2017-10-31 17:32:58
将Maven项目转换为SpringBoot
的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:
的情况下使用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
发布于 2018-08-13 02:09:46
1)在Pom.xml文件中添加Spring boot starter Parent和Web
2)在主类中添加@SpringBootApplication
3)在main方法中添加SpringApplication.run(App.class,args);。
https://stackoverflow.com/questions/29360631
复制相似问题