[SPRING] <context : include-filter>와 <context : exclude-filter>는 Spring에서 어떻게 작동합니까?
SPRING와 는 Spring에서 어떻게 작동합니까?
몇 가지 서비스가 있습니다.
@Service 주석이 주석 처리됩니다. 어떻게 하나를 제외한 모든 서비스를 제외 할 수 있습니까?
예를 들어 MailService 만 사용하려고합니다. 다음 구성을 사용합니다.
<context:component-scan base-package="example">
<context:include-filter type="aspectj" expression="example..MailService*" />
<context:exclude-filter type="aspectj" expression="example..*Service*" />
</context:component-scan>
그러나 지금 모든 서비스는 제외됩니다.
MailService를 포함하는 규칙이 하나라도있는 경우 모든 서비스가 제외되는 이유는 무엇입니까?
해결법
-
==============================
1.포함 필터는 제외 필터 다음에 적용되므로 두 표현식을 하나의 제외 필터로 결합해야합니다. AspectJ 표현식은 그것을 허용한다 (XML 구문 때문에 &로 대체된다) :
포함 필터는 제외 필터 다음에 적용되므로 두 표현식을 하나의 제외 필터로 결합해야합니다. AspectJ 표현식은 그것을 허용한다 (XML 구문 때문에 &로 대체된다) :
<context:exclude-filter type="aspectj" expression="example..*Service* && !example..MailService*" />
이것은 정규식이므로 표현식 ". * 서비스"는 "임의의 문자와 그 뒤에"서비스 "가 오는 숫자를 의미합니다. 이것은 명시 적으로 포함시키고 자하는 MailService를 제외시킵니다.
-
==============================
2.이 등록을 수행하는 또 다른 방법은 단일 포함 필터를 사용하는 것입니다.
이 등록을 수행하는 또 다른 방법은 단일 포함 필터를 사용하는 것입니다.
<context:component-scan base-package="example" use-default-filters="false"> <context:include-filter type="aspectj" expression="example..MailService*" /> </context:component-scan>
이 경우 스프링에 "default-filters"속성을 추가하지 않도록 "use-default-filters"속성을 "false"로 설정해야합니다.
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
-
==============================
3.필터 유형 "regex"를 사용하려는 것 같습니다. 다음은 Spring Reference의 예제이다.
필터 유형 "regex"를 사용하려는 것 같습니다. 다음은 Spring Reference의 예제이다.
<beans> <context:component-scan base-package="org.example"> <context:include-filter type="regex" expression=".*Stub.*Repository"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> </beans>
from https://stackoverflow.com/questions/3710444/how-do-contextinclude-filter-and-contextexclude-filter-work-in-spring by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] JUnit 테스트는 항상 트랜잭션을 롤백합니다. (0) | 2019.02.01 |
---|---|
[SPRING] @Autowired Map을 만들 수 있습니까? (0) | 2019.02.01 |
[SPRING] 스프링 MVC : 경로 변수가 필요한지 여부를 나타내는 방법? (0) | 2019.02.01 |
[SPRING] spring-boot-startter-web을 사용하여 "수용 가능한 표현을 찾을 수 없습니다" (0) | 2019.02.01 |
[SPRING] JPA는 분리 된 객체를 삭제한다고 생각합니다. (0) | 2019.02.01 |