본문 바로가기

명사 美 비격식 (무리 중에서) 아주 뛰어난[눈에 띄는] 사람[것]

Backend/Spring

(91)
Annotation - @Getter @Setter @ToString lombok에서 getter, setter, tostring의 역할을 대신하여 코드의 길이를 줄여준다. import lombok.Getter; import lombok.Setter; import lombok.ToString; @Getter @Setter @ToString public class Person { private String name; private int age; private String address; } @Getter Class 내 모든 필드의 Getter method를 자동 생성 @Setter Class 내 모든 필드의 Setter method를 자동 생성 @ToString Class 내 모든 필드의 toString method를 자동 생성 https://standout.tistory..
Annotation - @mapper @Select @Insert @Update @Delete @mapper MyBatis에서 인터페이스를 기반으로 SQL 매핑을 제공하는 어노테이션 XML 파일 없이 SQL 쿼리를 실행할 수 있다. @Mapper public interface UserMapper { @Select("SELECT * FROM users WHERE id = #{id}") User findById(Long id); @Insert("INSERT INTO users(name, age) VALUES(#{name}, #{age})") void save(User user); @Update("UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id}") void update(User user); @Delete("DELETE FROM users ..
Annotation - @SpringBootConfiguration @SpringBootConfiguration @Configuration 어노테이션의 특수한 경우 Spring Boot 애플리케이션에서는 일반적으로 @Configuration 어노테이션이 구성 클래스를 나타내는데, @SpringBootConfiguration은 @Configuration 어노테이션을 상속하며 Spring Boot의 *추가 구성 기능을 사용할 수 있도록 한다. * mvc자동구성, 외부파일에서로드할 수있어 다시 빌드하지않고도 구성정보를 변경, 다양한 환경에서 실행할 수 있도록 프로파일제공, 내장형서버를 사용하여 애플리케이션을 빠르게 시작 import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot..
Annotation - @EnableAutoConfiguration @EnableAutoConfiguration Spring Boot 애플리케이션에서 다양한 라이브러리들의 자동 구성을 활성화 @SpringBootApplication @EnableAutoConfiguration public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } https://standout.tistory.com/486 Annotation - @SpringBootApplication @SpringBootApplication 세 가지 Spring 어노테이션이 조합된 메타 어노테이션 어플리케이션 자동 구성 및 컴포넌트 검색을 위한 기본 설정을 모두 포함 단독으로, 조합으..
Annotation - @SpringBootApplication @SpringBootApplication 세 가지 Spring 어노테이션이 조합된 메타 어노테이션 = @Configuration, @EnableAutoConfiguration, @ComponentScan 3가지를 하나의 애노테이션으로 합친 것 어플리케이션 자동 구성 및 컴포넌트 검색을 위한 기본 설정을 모두 포함 단독으로, 조합으로 사용될 수 있다. @SpringBootApplication @ComponentScan(basePackages = "com.example.myapp") public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } @Sp..
Annotation - @ComponentScan @ComponentScan 지정된 패키지 및 하위 패키지에서 기본적으로 어플리케이션의 메인 클래스에 선언. Spring Component로 등록되어야 하는 클래스들을 검색한다. = @Component, @Service, @Repository, @Controller, @Configuration이 붙은 클래스 Bean들을 찾아 Context에 bean등록한다. @SpringBootApplication @ComponentScan(basePackages = "com.example.myapp") public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }..
Annotation - @Configuration @Configuration Spring Framework가 해당 클래스를 구성 클래스로 인식하고 구성을 위해 사용한다. 다른클래스에서 @Autowired로 Bean을 부를 수 있다. import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MyConfiguration { @Bean public MyBean myBean() { return new MyBean(); } } MyBean의 인스턴스를 생성하고 이를 애플리케이션의 다른 구성요소에서 사용할 수 있다. 구성클래스에는 빈, 데이터베이스연결 등이 포함될 수 있다..
Annotation - @Repository @Repository DAO class에서 쓰임 데이터베이스와 연동하여 데이터를 저장하거나 조회하는 데이터 계층의 클래스 @Repository public class UserRepository { @Autowired private JdbcTemplate jdbcTemplate; public User findById(Long id) { String sql = "SELECT * FROM user WHERE id = ?"; return jdbcTemplate.queryForObject(sql, new Object[] { id }, new UserRowMapper()); } } https://standout.tistory.com/477 Annotation - @Autowired @Qualifier @Autowi..
Annotation - @Service @Service 서비스 계층에서 사용되는 클래스임을 알림 public class UserService { @Autowired private UserRepository userRepository; public User getUserById(Long id) { return userRepository.findById(id).orElse(null); } public User saveUser(User user) { return userRepository.save(user); } } https://standout.tistory.com/477 Annotation - @Autowired @Qualifier @Autowired 메서드 파라미터에 맞는 타입의 빈을 찾아서 자동으로 주입 의존성 주입(Dependency In..
Annotation - @PostMapping @PostMapping HTTP POST 요청을 처리 @RequestMapping(Method=RequestMethod.POST)와 같다. @Controller public class HomeController { @PostMapping("/") public String home() { return "home"; } } https://standout.tistory.com/478 Annotation - @Controller @Controller @Component 어노테이션의 특수한 종류 Spring MVC에서 Controller클래스 HTTP 요청을 처리하고, 적절한 비즈니스 로직을 호출 @Controller @RequestMapping("/user") public class UserController ..
Annotation - @GetMapping @GetMapping HTTP GET 요청을 처리 @RequestMapping(Method=RequestMethod.GET)와 같다. @Controller public class HomeController { @GetMapping("/") public String home() { return "home"; } } / URL 경로에 대한 GET 요청을 처리 https://standout.tistory.com/478 Annotation - @Controller @Controller @Component 어노테이션의 특수한 종류 Spring MVC에서 Controller클래스 HTTP 요청을 처리하고, 적절한 비즈니스 로직을 호출 @Controller @RequestMapping("/user") public c..
Annotation - @RequestMapping @RequestMapping 요청 URL을 어떤 컨트롤러 메서드로 처리할지 매핑 @Controller @RequestMapping("/users") public class UserController { @Autowired private UserService userService; @GetMapping("/{id}") public String getUser(@PathVariable Long id, Model model) { User user = userService.getUserById(id); model.addAttribute("user", user); return "userView"; } } URL매핑으로, http://~/users/{id} URL에 대한 GET 요청을 처리 https://stando..
Annotation - @Controller @Controller @Component 어노테이션의 특수한 종류 Spring MVC에서 Controller클래스 HTTP 요청을 처리하고, 적절한 비즈니스 로직을 호출 @Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @GetMapping("/{id}") public String getUser(@PathVariable Long id, Model model) { User user = userService.getUserById(id); model.addAttribute("user", user); return "userView"; } @PostMapping("/..
Annotation - @Autowired @Qualifier @Autowired 메서드 파라미터에 맞는 타입의 빈을 찾아서 자동으로 주입 의존성 주입(Dependency Injection)을 자동화하는 데 사용되는 어노테이션 속성(field), setter method, constructor(생성자)에서 사용된다. @Component public class MyClass { @Autowired private MyDependency myDependency; } @Qualifier @Autowired와 함께 사용된다. 같은 타입의 빈이 둘 이상인 경우, 에러를 발생시키거나, @Qualifier 어노테이션을 사용하여 해당 아이디를 적어주어 특정 빈을 선택할 수 있다. @Component public class MyComponent { @Autowired @Qualifi..
Annotation - @Component @Component 개발자가 직접 작성한 Class를 Bean으로 등록하기 위한 Annotation 스프링 MVC에서는 @Component 어노테이션의 특화된 형태인 @Controller, @Service, @Repository 등이 사용된다. @Component public class MyComponent {} https://standout.tistory.com/474 Annotation - @Bean @Scope @Bean 빈은 Spring 컨테이너에서 생성되고 관리되는 객체 개발자가 직접 제어가 불가능한 외부 라이브러리등을 Bean으로 만들려할 때 주로 사용된다. @Configuration public class MyConfiguration { @Bean public MyBe standout.tis..
@Component와 @Bean의 차이 @Component 어노테이션은 클래스 레벨에서 사용 @Bean 어노테이션은 메서드 레벨에서 사용 https://standout.tistory.com/474 Annotation - @Bean @Scope @Bean 빈은 Spring 컨테이너에서 생성되고 관리되는 객체 개발자가 직접 제어가 불가능한 외부 라이브러리등을 Bean으로 만들려할 때 주로 사용된다. @Configuration public class MyConfiguration { @Bean public MyBe standout.tistory.com https://standout.tistory.com/476 Annotation - @Component @Component 개발자가 직접 작성한 Class를 Bean으로 등록하기 위한 Annotation..
Annotation - @Bean @Scope @Bean 빈은 Spring 컨테이너에서 생성되고 관리되는 객체 개발자가 직접 제어가 불가능한 외부 라이브러리등을 Bean으로 만들려할 때 주로 사용된다. @Configuration public class MyConfiguration { @Bean public MyBean myBean() { return new MyBean(); } } @Scope @Bean 애너테이션은 @Scope로 빈의 범위 및 생명주기와 같은 다양한 옵션을 구성할 수 있다. @Bean @Scope("prototype") public MyBean myBean() { return new MyBean(); } Singleton: 기본값, 애플리케이션 전체에서 하나의 인스턴스를 생성하고 공유 Prototype: 요청이 있을 때마다 새로운 ..
공통처리 삼총사, Filter Interceptor AOP 공통처리 삼총사, Filter Interceptor AOP 1. Filter 2. Interceptor 3. AOP 요청시 아래의 순서로 실행 Filter → Interceptor → AOP → Interceptor → Filter 순 Filter 한글처리를 위한 인코딩 필터와 같은 자원의 앞단에서 요청내용을 변경하거나, 여러가지 체크를 수행 init() - 필터 인스턴스 초기화 doFilter() - 전/후 처리 destroy() - 필터 인스턴스 종료 Interceptor DistpatcherServlet이 컨트롤러를 호출하기 전, 후 로 가로챔 로그인 체크, 권한체크, 프로그램 실행시간 계산작업 로그확인 등을 수행 preHandler() - 컨트롤러 메서드가 실행되기 전 postHanler() - ..
Spring boot, thymeleaf static 파일 인식오류, 404에러 첫 spring boot 프로젝트, 첫 웹페이지를 띄웠을때 파일을 인식하지못해 지속적으로 404에러가 떴다. 재시작, 포트변경, 파일경로변경 등을 해도 해결되지않았다. 절대경로를 입력해도 404에러가 뜨는 순간 무언가 다른 문제가 생겼다고 판단했다. 서치를해도 자바나 설정등의 파일에 추가코드를 입력하라는데, 기본적으로 static을 인식하는 springBoot에게 왜 추가정보를 주어야 하는지 이해가되지않아 좀 더 이것저것 건드려보고 추후에 추가해보기로 했다. th:action="@{}"코드를 추가해 비교해보자. ..? 경로를 잘 잡는다. 이후 추가했던 타임리프코드 th:action="@{}"를 삭제후 다시 돌려보니.. 거짓말같이 잘된다. 무슨 오류일까.. 첫스프링부트, 첫웹페이지를 띄우는 중간 만약 필자..
error setting null for parameter #n Controller에서 (+ mapper, sql.xml) 에서 아직 구현되지않지만 미리 넣어놓은 변수들이 있다면 주석처리해보자. 테이블 값이 null을 허용했으니 괜찮을거라 생각되지만 적절히 구현해놓지않아 받지못한 null값은 에러를 발생시킨다.
스프링프레임워크 Property 네임스페이스 이용하기 p 네임스페이스 이용하기 p:변수명-ref="객체이름/아이디" p:변수명="설정할값" Bean의 프로퍼티는 해당 Bean의 속성 값 Property 네임스페이스를 사용하면 Bean의 프로퍼티 값을 XML 파일에서 직접 지정할 수 있다.
javax.annotation.Resource import 안될때 pom.xml에 아래의 코드를 추가/수정해보자. javax.annotation javax.annotation-api 1.3.1
java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allPointcut참조된 포인트컷을 찾을 수 없습니다 Asepectj 로그 버전이 낮다면,1.8.14로 높여보자. org.aspectj aspectjrt 1.8.14 org.aspectj aspectjweaver 1.8.14 runtime
spring-context 4.1.1.RELEASE 란? 스프링 애플리케이션 핵심 컨테이너 pom.xml에 추가 org.springframework spring-context 4.1.1.RELEASE https://mvnrepository.com/artifact/org.springframework/spring-context/4.1.1.RELEASE
spring-webmvc 4.1.1.RELEASE 란? 스프링 MVC 핵심 모듈, 컨트롤러, 뷰(view), 모델(model) 상호작용 pom.xml에 추가 org.springframework spring-webmvc 4.1.1.RELEASE https://mvnrepository.com/artifact/org.springframework/spring-webmvc/4.1.1.RELEASE
spring-aop 4.1.1.RELEASE 란? 애너테이션을 사용해 로직을 추가 pom.xml에 추가 org.springframework spring-aop 4.1.1.RELEASE https://mvnrepository.com/artifact/org.springframework/spring-aop/4.1.1.RELEASE
aspectjrt 1.6.10 이란? AspectJ 애플리케이션 실행 pom.xml에 추가 org.aspectj aspectjrt 1.6.10 runtime https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.6.10
aspectjweaver 1.6.10 이란? 런타임에 AOP기능을 적용 pom.xml에 추가 org.aspectj aspectjweaver 1.6.10 runtime https://mvnrepository.com/artifact/org.aspectj/aspectjweaver/1.6.10
aspectjtools 1.6.10 이란? 컴파일, 디버깅 기능제공 pom.xml에 추가 org.aspectj aspectjtools 1.6.10 https://mvnrepository.com/artifact/org.aspectj/aspectjtools/1.6.10
slf4j-api 1.6.6 이란? 로깅을 위한 인터페이스 제공 pom.xml에 추가 org.slf4j slf4j-api 1.6.6 https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.6.6