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
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>
I will face this question in two more interviews so it can help full your self also.
Simply right-click on your project select "Configure" and choose on "convert to Maven Project" then it will create or application as maven and .
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.
Convert Maven Project to SpringBoot
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>
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
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