컨트롤러 객체 없이 뷰에 요청 전달하기 웹 애플리케이션에서 요청이 오면 그에 해당하는 컨트롤러 객체가 필요하다. 하지만 단순 페이지만 사용자에게 보여주기 위해서는 굳이 컨트롤러 객체가 필요하지 않을 수 있다. 아래 예제를 통해 알아보았다. 예제WebConfig.java@Configurationpublic class WebConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { // 요청 url: / registry.addViewController("/").setViewName("home"); // 요청 url: /no-view, 요청 페이지 없음 re..
프로토타입 빈과 싱글톤 빈을 함께 사용 시 문제점 프로토 타입 빈과 싱글톤 빈을 함께 사용하면 의도한 대로 잘 동작하지 않을 수 있다. 아래 코드를 통해 알아보았다. 예제 아래 코드는 싱글톤 빈 내부에 있는 프로토타입 빈이 있을 때 2개의 클라이언트가 각각 싱글톤을 주입받으면 내부에 있는 프로토타입이 새로 생성되는지 알아보는 코드이다.public class SingletonWithPrototypeTest { @Test void singletonClientUsePrototype() { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ClientBean.class, ..
의존 관계 주입 방법생성자 주입수정자 주입(setter 주입)필드 주입일반 메서드 주입 생성자 주입 생성자를 통해서 의존 관계를 주입하는 것이다. 객체의 생성과 동시에 주입하며 불변, 필수 의존관계에 사용한다.@Servicepublic class ExService { private final ExRepository exRepository; // 생성자가 1개일 때 @Autowired 생략 가능 // @Autowired public exService(ExRepository exRepository) { this.exRepository = exRepository; }}※ 생성자가 1개만 있으면 @Autowired 생략 가능하다. 수정자 주입 setter라 불리는 ..
스프링 초기화 시점에서의 트랜잭션 AOP 적용 아래 예제를 통해 스프링 초기화 시점에서 트랜잭션이 적용되는지 테스트해보았다. 트랜잭션 적용X@SpringBootTestpublic class InitTest { @Test void execute() {} @TestConfiguration static class InitTestConfig { @Bean InitClass initClass() { return new InitClass(); } } @Slf4j static class InitClass { @PostConstruct @Transactional public void in..
