Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以将Maven项目转换为SpringBoot吗_Java_Spring_Eclipse_Maven_Spring Boot - Fatal编程技术网

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

Java 我可以将Maven项目转换为SpringBoot吗,java,spring,eclipse,maven,spring-boot,Java,Spring,Eclipse,Maven,Spring Boot,我在Eclipse中有一个Maven项目,现在我需要添加数据库连接。我的教科书用Maven编写了所有json教程。现在在关于JDBC的这一章中,他们正在使用SpringBoot 我可以将项目转换为SpringBoot吗?或者启动一个SpringBoot并导入我以前的Maven类。如何将Maven用于SpringBoot项目 您需要修改现有的pom.xml以添加类似的内容,使其成为SpringBoot项目: <!-- Inherit defaults from Spring Boot --&

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

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

如何将Maven用于SpringBoot项目

您需要修改现有的
pom.xml
以添加类似的内容,使其成为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>

org.springframework.boot
spring启动程序父级
1.2.2.1发布
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
springbootmaven插件

将Maven项目转换为SpringBoot

  • Ist选项:使用父POM的Spring引导
在pom.xml文件**中添加以下依赖项:-

1.继承starter父级(spring boot starter父级):spring boot starter父级是一种特殊的启动程序,提供了有用的Maven默认值

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

3.spring boot maven插件:spring boot包含一个maven插件,可以将项目打包为可执行的jar

以下是pom.xml:-


org.springframework.boot

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

2) 在主类中添加@SpringBootApplication


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

是的,您可以使用Springboot和Maven作为依赖项管理。 您必须添加spring引导依赖项

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

org.springframework.boot
spring启动程序父级
1.3.5.1发布

另外,在主类中添加@springbootplication和@EnableAutoConfiguration

我将在另外两次采访中面对这个问题,这样它也可以帮助你充实自己。


只需右键单击您的项目,选择“配置”并选择“转换为Maven项目”,然后它将以Maven和的形式创建或应用程序。

看看这个,您可以从spring boot pom.xml和父项以及必要的内容中添加适当的依赖项。这是一篇旧文章,因此仅供将来参考。springboot无疑是一种有效的(对许多人来说,更可取的)添加数据库连接的方法。然而,这绝不是唯一的办法。您不必在项目中使用SpringBoot来与JDBC通信。它可以通过包含必要的依赖项来完成。这是由提供的、是否接受的确切链接。这似乎不能回答这个问题。(不管链接的内容是否可能:参见)如果没有主类会怎么样?如果它是像库模块那样的子模块呢?
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>