Can I convert Maven Project to SpringBoot

后端 未结 5 812
滥情空心
滥情空心 2021-02-06 00:00

I have a Maven Project in Eclipse and now I need to add database connectivity. My textbook did all json tutorials in Maven. Now in this chapter on JDBC they are using SpringBoot

相关标签:
5条回答
  • 2021-02-06 00:39

    Here is described how to use maven for a SpringBoot Project.

    You will need to modify your existing pom.xml to add something like this to make it a SpringBoot Project:

    <!-- 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>
    
    0 讨论(0)
  • 2021-02-06 00:40

    I will face this question in two more interviews so it can help full your self also. Converting the standard alone application to spring boot

    Simply right-click on your project select "Configure" and choose on "convert to Maven Project" then it will create or application as maven and explicitly add maven dependencies which we want to required.

    0 讨论(0)
  • 2021-02-06 00:53

    1) Add Spring boot starter Parent and Web in Pom.xml file

    2) Add @SpringBootApplication in the main class

    3) Add SpringApplication.run(App.class, args); in main method.

    0 讨论(0)
  • 2021-02-06 00:54

    Convert Maven Project to SpringBoot

    • Ist option :Spring Boot Using parent POM

    Add following dependencies in pom.xml file**:-

    1.) Inheriting the starter parent(spring-boot-starter-parent): spring-boot-starter-parent is a special starter that provides useful Maven defaults.

    2.) spring-boot-starter-web :- Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.

    3.) spring-boot-maven-plugin:- Spring Boot includes a Maven plugin that can package the project as an executable jar.

    here is pom.xml :-

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.7.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>
    

    • 2nd option:Using Spring Boot without the Parent POM

    Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configuration.

    If you do not want to use the spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency, as follows:

    < dependency> < !-- Import dependency management from Spring Boot -->
    < groupId>org.springframework.boot< /groupId>
    < artifactId>spring-boot-dependencies< /artifactId>
    < version>2.0.0.BUILD-SNAPSHOT< /version> < type>pom< /type>
    < scope>import< /scope> < /dependency>

    Fore more details find here in Spring Boot Docs:- https://docs.spring.io/spring-boot/docs/1.4.7.RELEASE/reference/htmlsingle/#getting-started-maven-installation

    0 讨论(0)
  • 2021-02-06 01:00

    Yes you can use Springboot with Maven as dependency management. You will have to add spring boot dependencies

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

    Also add @SpringBootApplication and @EnableAutoConfiguration in the main class

    0 讨论(0)
提交回复
热议问题