In pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SpringBootDataJpaStoredProcedureEx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootDataJpaStoredProcedureEx</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
In application.properties
# database properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springbootdatalearndb
spring.datasource.username=root
spring.datasource.password=123456
# spring data jpa properties
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
In Employee.java
package com.example.models;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "sp_employee_table")
public class Employee {
@Id
private Integer empId;
private String empName;
private String empDesg;
private String empDept;
private Double empSal;
}
In EmployeeRepository.java
package com.example.repositories;
import com.example.models.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
}
In DataInsertRunner.java
package com.example.runners;
import com.example.models.Employee;
import com.example.repositories.EmployeeRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DataInsertRunner implements CommandLineRunner {
@Autowired
private EmployeeRepository employeeRepository;
@Override
public void run(String... args) throws Exception {
log.info("DataInsertRunner execution started.");
employeeRepository.save(new Employee(101, "SAM", "Lead", "DEV", 86500.0));
employeeRepository.save(new Employee(102, "RAM", "MGR", "DEV", 96000.0));
employeeRepository.save(new Employee(103, "SYED", "ASSOCIATE", "QA", 32500.0));
employeeRepository.save(new Employee(104, "ABD", "MGR", "BA", 55500.0));
log.info("DataInsertRunner execution completed.");
}
}
In StarterClass (SpringBootDataJpaStoredProcedureExApplication.java)
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootDataJpaStoredProcedureExApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootDataJpaStoredProcedureExApplication.class, args);
}
}
Console:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.3)
2023-02-25T14:48:44.900+05:30 INFO 13732 --- [ restartedMain] gBootDataJpaStoredProcedureExApplication : Starting SpringBootDataJpaStoredProcedureExApplication using Java 17.0.4.1 with PID 13732 (G:\Java\IntelliJ Workspace\Learning\Spring Boot By Raghu\Spring Boot Data\SpringBootDataJpaStoredProcedureEx\target\classes started by himan in G:\Java\IntelliJ Workspace\Learning\Spring Boot By Raghu\Spring Boot Data\SpringBootDataJpaStoredProcedureEx)
2023-02-25T14:48:44.903+05:30 INFO 13732 --- [ restartedMain] gBootDataJpaStoredProcedureExApplication : No active profile set, falling back to 1 default profile: "default"
2023-02-25T14:48:44.954+05:30 INFO 13732 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-02-25T14:48:45.382+05:30 INFO 13732 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-02-25T14:48:45.400+05:30 INFO 13732 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10 ms. Found 0 JPA repository interfaces.
2023-02-25T14:48:45.785+05:30 INFO 13732 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-02-25T14:48:45.837+05:30 INFO 13732 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.7.Final
2023-02-25T14:48:46.177+05:30 INFO 13732 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-02-25T14:48:46.600+05:30 INFO 13732 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@27cbf856
2023-02-25T14:48:46.602+05:30 INFO 13732 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-02-25T14:48:46.657+05:30 INFO 13732 --- [ restartedMain] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2023-02-25T14:48:46.975+05:30 INFO 13732 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-02-25T14:48:46.987+05:30 INFO 13732 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-02-25T14:48:47.136+05:30 INFO 13732 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-02-25T14:48:47.157+05:30 INFO 13732 --- [ restartedMain] gBootDataJpaStoredProcedureExApplication : Started SpringBootDataJpaStoredProcedureExApplication in 2.637 seconds (process running for 3.445)
2023-02-25T14:48:47.165+05:30 INFO 13732 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-02-25T14:48:47.169+05:30 INFO 13732 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-02-25T14:48:47.179+05:30 INFO 13732 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0
As you can see when I am using Spring Boot-3.0.3, there is no bean created for runner i.e., DataInsertRunner and it is not even called at application startup. But when I am using Spring Boot-3.0.2, It is working fine. I have checked documentation of Spring Boot-3.0.3 for any update, but did not find anything new about runner or bean creation. So, please suggest me if any update have been made related to runner or bean creation.
Link of above project using spring boot 3.0.3
Link of above project using spring boot 3.0.2
I am trying to insert data into mysql database at application startup using runner.
This behavior is due to a regression in Spring Framework 6.0.5. You can work around the problem by not having any spaces in your application's path. Alternatively, downgrading to Spring Framework 6.0.4 should also work.