Lazy Initialization :
hitarth's Vault // Exported at - 10:04:PM
package com.example.demo.examples.jakarta;
import com.example.demo.businessAssignment.components.DataService;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jdk.jfr.Name;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.Arrays;
//@Component
@Named // we can use @Named and @Inject instead of @Component and @Inject respectively
class BusinessService {
private DataService2 dataService;
// @Autowired
@Inject
public void setDataService(DataService2 dataService) {
System.out.println("Setter called");
this.dataService = dataService;
}
public DataService2 getDataService() {
System.out.println("Setter injection");
return dataService;
}
}
//@Component
@Named
class DataService2 {
}
@Configuration
@ComponentScan // performs a component scan on the current package
public class CdiContextLauncherApp {
public static void main(String[] args) {
var context = new AnnotationConfigApplicationContext(CdiContextLauncherApp.class);
Arrays.stream(context.getBeanDefinitionNames()).forEach((System.out::println));
System.out.println(context.getBean(BusinessService.class).getDataService());
}
}
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Picking up configs from application.properties
file
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
user=SA
partBoth the code blocks will perform the same task but the Spring JDBC requires less code compared to JDBC
indexing : command line runner, jdbc, sql, insert into, @Repository, JdbcTemplate
<Course, Integer>
integer is the ID type
or
<form method="post">...</form>
is to be used whenever you want to transfer the data
get
method reveals the name and password in the URL
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>glassfish-jstl</artifactId>
</dependency>
Description: <input type="text" name="description" required/>