필터는 Spring 외부 영역에 있다.
다른 클래스와 다르게 외부 생성자를 @Autowired 통해서 바로 갖고 올수없고
Bean 에 등록된 것만 갖고 올수있다.
root-context.xml 에서
<bean id="test" class="~~~~~~">
<property name="~~~~~" ref="~~~~~" />
</bean>
이런식으로 있는 bean 을 추가하여
filter 클래스에서
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
this. test = ( Test ) ctx.getBean(" test ");
}
이런식으로 init 에서 Bean 에 있는 정보를 갖고와서 쓰면 됐었다.
'자바' 카테고리의 다른 글
| JPA @Transactional(readOnly = true) (0) | 2024.04.12 |
|---|---|
| Arrays.binarySearch , 이진 검색 알고리즘 (0) | 2024.03.14 |
| 티스토리 java 코드 쓸때 주위 블럭 여백 없애기 (0) | 2023.09.05 |
| Java split(조건)으로 문자열 나누기 (0) | 2023.09.05 |
| 이클립스 코드 수정 사항 적용 안될 때 해결 방법 (0) | 2023.07.28 |