Spring Boot
Introduction
Problem
Initially, we need to do the configuration one by one, such as spring container , hibernate, security, servlet, jackson
We need to search for the dependency and enter into pom.xml one by one
We need to install tomcat manually to host the application
Solution
The annotation of spring boot application is already included component scanning, configuration and property source ( default : reading application.properties)
@SpringBootApplication
public class CruddemoApplication {
public static void main(String[] args) {
SpringApplication.run(CruddemoApplication.class, args);
}
}The dependency of spring boot starter web already include jackson ,spring-core, spring-mvc, hibernate-validator
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>The spring boot application contains embedded tomcat, so we can just run command mvnw package and mvnw spring-boot:run to start the application
Hibernate
Configuration
Initially, we need to do a long long configuration to create session factory and transaction manager
After using spring boot, we can just easily enter the path of sql table , username and password in application properties , the entity manager (which is similar with session factory ) will be generated automatically
Operation (CRUD) (Without Spring Data)
Session Factory
Read the hibernate config file
Generate the session object
Session
Wrap in a JDBC Connection
Used to perform CRUD Operation
Example
Operation (CRUD) (With Spring Data)
Spring data contains interface that include default crud method
we can just make good use of this without define the method manually
Last updated
Was this helpful?