Skip to content

Commit a471aa6

Browse files
committed
Use code includes and tabs in Regexp Pointcuts documentation
See gh-22171
1 parent 515295e commit a471aa6

File tree

7 files changed

+182
-27
lines changed

7 files changed

+182
-27
lines changed

framework-docs/modules/ROOT/pages/core/aop-api/pointcuts.adoc

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,40 +128,15 @@ the resulting pointcut is effectively the union of the specified patterns.)
128128

129129
The following example shows how to use `JdkRegexpMethodPointcut`:
130130

131-
[source,xml,indent=0,subs="verbatim"]
132-
----
133-
<bean id="settersAndAbsquatulatePointcut"
134-
class="org.springframework.aop.support.JdkRegexpMethodPointcut">
135-
<property name="patterns">
136-
<list>
137-
<value>.*set.*</value>
138-
<value>.*absquatulate</value>
139-
</list>
140-
</property>
141-
</bean>
142-
----
131+
include-code::./JdkRegexpConfiguration[tag=snippet,indent=0]
143132

144133
Spring provides a convenience class named `RegexpMethodPointcutAdvisor`, which lets us
145134
also reference an `Advice` (remember that an `Advice` can be an interceptor, before advice,
146135
throws advice, and others). Behind the scenes, Spring uses a `JdkRegexpMethodPointcut`.
147136
Using `RegexpMethodPointcutAdvisor` simplifies wiring, as the one bean encapsulates both
148137
pointcut and advice, as the following example shows:
149138

150-
[source,xml,indent=0,subs="verbatim"]
151-
----
152-
<bean id="settersAndAbsquatulateAdvisor"
153-
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
154-
<property name="advice">
155-
<ref bean="beanNameOfAopAllianceInterceptor"/>
156-
</property>
157-
<property name="patterns">
158-
<list>
159-
<value>.*set.*</value>
160-
<value>.*absquatulate</value>
161-
</list>
162-
</property>
163-
</bean>
164-
----
139+
include-code::./RegexpConfiguration[tag=snippet,indent=0]
165140

166141
You can use `RegexpMethodPointcutAdvisor` with any `Advice` type.
167142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.docs.core.aopapi.aopapipointcutsregex;
18+
19+
import org.springframework.aop.support.JdkRegexpMethodPointcut;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
// tag::snippet[]
24+
@Configuration
25+
public class JdkRegexpConfiguration {
26+
27+
@Bean
28+
public JdkRegexpMethodPointcut settersAndAbsquatulatePointcut() {
29+
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
30+
pointcut.setPatterns(".*set.*", ".*absquatulate");
31+
return pointcut;
32+
}
33+
}
34+
// end::snippet[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.docs.core.aopapi.aopapipointcutsregex;
18+
19+
import org.aopalliance.aop.Advice;
20+
21+
import org.springframework.aop.support.RegexpMethodPointcutAdvisor;
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
// tag::snippet[]
26+
@Configuration
27+
public class RegexpConfiguration {
28+
29+
@Bean
30+
public RegexpMethodPointcutAdvisor settersAndAbsquatulateAdvisor(Advice beanNameOfAopAllianceInterceptor) {
31+
RegexpMethodPointcutAdvisor advisor = new RegexpMethodPointcutAdvisor();
32+
advisor.setAdvice(beanNameOfAopAllianceInterceptor);
33+
advisor.setPatterns(".*set.*", ".*absquatulate");
34+
return advisor;
35+
}
36+
}
37+
// end::snippet[]
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.docs.core.aopapi.aopapipointcutsregex
18+
19+
import org.springframework.aop.support.JdkRegexpMethodPointcut
20+
import org.springframework.context.annotation.Bean
21+
import org.springframework.context.annotation.Configuration
22+
23+
// tag::snippet[]
24+
@Configuration
25+
class JdkRegexpConfiguration {
26+
27+
@Bean
28+
fun settersAndAbsquatulatePointcut() = JdkRegexpMethodPointcut().apply {
29+
setPatterns(".*set.*", ".*absquatulate")
30+
}
31+
}
32+
// end::snippet[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.docs.core.aopapi.aopapipointcutsregex
18+
19+
import org.aopalliance.aop.Advice
20+
import org.springframework.aop.support.RegexpMethodPointcutAdvisor
21+
import org.springframework.context.annotation.Bean
22+
import org.springframework.context.annotation.Configuration
23+
24+
// tag::snippet[]
25+
@Configuration
26+
class RegexpConfiguration {
27+
28+
@Bean
29+
fun settersAndAbsquatulateAdvisor(beanNameOfAopAllianceInterceptor: Advice) = RegexpMethodPointcutAdvisor().apply {
30+
advice = beanNameOfAopAllianceInterceptor
31+
setPatterns(".*set.*", ".*absquatulate")
32+
}
33+
}
34+
// end::snippet[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
https://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<!-- tag::snippet[] -->
8+
<bean id="settersAndAbsquatulatePointcut"
9+
class="org.springframework.aop.support.JdkRegexpMethodPointcut">
10+
<property name="patterns">
11+
<list>
12+
<value>.*set.*</value>
13+
<value>.*absquatulate</value>
14+
</list>
15+
</property>
16+
</bean>
17+
<!-- end::snippet[] -->
18+
19+
</beans>
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
https://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<!-- tag::snippet[] -->
8+
<bean id="settersAndAbsquatulateAdvisor"
9+
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
10+
<property name="advice">
11+
<ref bean="beanNameOfAopAllianceInterceptor"/>
12+
</property>
13+
<property name="patterns">
14+
<list>
15+
<value>.*set.*</value>
16+
<value>.*absquatulate</value>
17+
</list>
18+
</property>
19+
</bean>
20+
<!-- end::snippet[] -->
21+
22+
</beans>

0 commit comments

Comments
 (0)