* Moved annotations articles to new spring-boot-annotations module
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Required;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
@DependsOn
|
||||
public class Bike implements Vehicle {
|
||||
|
||||
private String color;
|
||||
|
||||
@Required
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Biker {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("bike")
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Autowired
|
||||
public Biker(@Qualifier("bike") Vehicle vehicle) {
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setVehicle(@Qualifier("bike") Vehicle vehicle) {
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
@DependsOn("engine")
|
||||
public class Car implements Vehicle {
|
||||
|
||||
@Autowired
|
||||
private Engine engine;
|
||||
|
||||
@Autowired
|
||||
public Car(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setEngine(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Lazy
|
||||
public class CarMechanic {
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CarUtility {
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
|
||||
public class CustomException extends RuntimeException {
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Driver {
|
||||
|
||||
@Autowired
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Autowired
|
||||
public Driver(Vehicle vehicle) {
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setVehicle(Vehicle vehicle) {
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
public Vehicle getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 10000)
|
||||
@Scheduled(cron = "0 * * * * MON-FRI")
|
||||
public void checkVehicle() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
public class Engine {
|
||||
|
||||
@Value("8")
|
||||
private int cylinderCount;
|
||||
|
||||
@Value("${engine.fuelType}")
|
||||
private String fuelType;
|
||||
|
||||
public Engine() {
|
||||
this(8);
|
||||
}
|
||||
|
||||
public Engine(@Value("8") int cylinderCount) {
|
||||
this.cylinderCount = cylinderCount;
|
||||
}
|
||||
|
||||
@Value("8")
|
||||
public void setCylinderCount(int cylinderCount) {
|
||||
this.cylinderCount = cylinderCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class PerformanceAspect {
|
||||
|
||||
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());
|
||||
|
||||
@Pointcut("within(@org.springframework.stereotype.Repository *)")
|
||||
public void repositoryClassMethods() {
|
||||
}
|
||||
|
||||
@Around("repositoryClassMethods()")
|
||||
public Object measureMethodExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
|
||||
long start = System.nanoTime();
|
||||
Object retval = pjp.proceed();
|
||||
long end = System.nanoTime();
|
||||
String methodName = pjp.getSignature().getName();
|
||||
logger.info("Execution of " + methodName + " took " + TimeUnit.NANOSECONDS.toMillis(end - start) + " ms");
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
public interface Vehicle {
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/vehicles", method = RequestMethod.GET)
|
||||
public class VehicleController {
|
||||
|
||||
@CrossOrigin
|
||||
@ResponseBody
|
||||
@RequestMapping("/hello")
|
||||
public String hello() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
@RequestMapping("/home")
|
||||
public String home() {
|
||||
return "home";
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public void saveVehicle(@RequestBody Vehicle vehicle) {
|
||||
}
|
||||
|
||||
@RequestMapping("/{id}")
|
||||
public Vehicle getVehicle(@PathVariable("id") long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping
|
||||
public Vehicle getVehicleByParam(@RequestParam("id") long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping("/buy")
|
||||
public Car buyCar(@RequestParam(defaultValue = "5") int seatCount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public void onIllegalArgumentException(IllegalArgumentException exception) {
|
||||
}
|
||||
|
||||
@PostMapping("/assemble")
|
||||
public void assembleVehicle(@ModelAttribute("vehicle") Vehicle vehicle) {
|
||||
}
|
||||
|
||||
@ModelAttribute("vehicle")
|
||||
public Vehicle getVehicle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class VehicleFactoryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleFactoryApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "com.baeldung.annotations")
|
||||
@ComponentScan(basePackageClasses = VehicleFactoryConfig.class)
|
||||
@ImportResource("classpath:/annotations.xml")
|
||||
@PropertySource("classpath:/annotations.properties")
|
||||
@Lazy
|
||||
@EnableAutoConfiguration
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
public class VehicleFactoryConfig {
|
||||
|
||||
@Bean
|
||||
@Lazy(false)
|
||||
public Engine engine() {
|
||||
return new Engine();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class VehicleRepository {
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class VehicleRestController {
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.annotations;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class VehicleService {
|
||||
|
||||
@Async
|
||||
public void repairCar() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user