Skip to content

Commit f4bc9ff

Browse files
committed
Reintroduce component index support for Jakarta annotations
Spring Framework 6.0 GA introduced a regression in the component index support for Jakarta annotations such as @nAmed and @ManagedBean. Prior to this commit, @nAmed and @ManagedBean components were registered in the component index at build time; however, component scanning failed to find those component at run time. This commit updates ClassPathScanningCandidateComponentProvider so that `jakarta.*` annotation types are once again supported for component scanning via the component index at run time. Closes gh-29641
1 parent e124e80 commit f4bc9ff

File tree

7 files changed

+196
-81
lines changed

7 files changed

+196
-81
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
* @author Ramnivas Laddad
8080
* @author Chris Beams
8181
* @author Stephane Nicoll
82+
* @author Sam Brannen
8283
* @since 2.5
8384
* @see org.springframework.core.type.classreading.MetadataReaderFactory
8485
* @see org.springframework.core.type.AnnotationMetadata
@@ -343,7 +344,7 @@ private boolean indexSupportsIncludeFilter(TypeFilter filter) {
343344
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
344345
Class<? extends Annotation> annotationType = annotationTypeFilter.getAnnotationType();
345346
return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotationType) ||
346-
annotationType.getName().startsWith("javax."));
347+
annotationType.getName().startsWith("jakarta."));
347348
}
348349
if (filter instanceof AssignableTypeFilter assignableTypeFilter) {
349350
Class<?> target = assignableTypeFilter.getTargetType();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2002-2022 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 example.indexed;
18+
19+
/**
20+
* @author Sam Brannen
21+
*/
22+
@jakarta.annotation.ManagedBean
23+
public class IndexedJakartaManagedBeanComponent {
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2002-2022 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 example.indexed;
18+
19+
/**
20+
* @author Sam Brannen
21+
*/
22+
@jakarta.inject.Named("myIndexedJakartaNamedComponent")
23+
public class IndexedJakartaNamedComponent {
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2002-2022 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 example.scannable;
18+
19+
/**
20+
* @author Sam Brannen
21+
*/
22+
@jakarta.annotation.ManagedBean
23+
public class JakartaManagedBeanComponent {
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2002-2022 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 example.scannable;
18+
19+
/**
20+
* @author Sam Brannen
21+
*/
22+
@jakarta.inject.Named("myJakartaNamedComponent")
23+
public class JakartaNamedComponent {
24+
}

0 commit comments

Comments
 (0)