diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
index f93c08f3d5..74fc92b97c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
@@ -461,7 +461,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
/**
* Register an externally managed configuration initialization method —
* for example, a method annotated with JSR-250's
- * {@link javax.annotation.PostConstruct} annotation.
+ * {@link jakarta.annotation.PostConstruct} annotation.
*
The supplied {@code initMethod} may be the
* {@linkplain Method#getName() simple method name} for non-private methods or the
* {@linkplain org.springframework.util.ClassUtils#getQualifiedMethodName(Method)
@@ -538,7 +538,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
/**
* Register an externally managed configuration destruction method —
* for example, a method annotated with JSR-250's
- * {@link javax.annotation.PreDestroy} annotation.
+ * {@link jakarta.annotation.PreDestroy} annotation.
*
The supplied {@code destroyMethod} may be the
* {@linkplain Method#getName() simple method name} for non-private methods or the
* {@linkplain org.springframework.util.ClassUtils#getQualifiedMethodName(Method)
diff --git a/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java b/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java
index 034452bc05..a481ce58b5 100644
--- a/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java
+++ b/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java
@@ -19,9 +19,8 @@ package org.springframework.context.annotation;
import java.util.ArrayList;
import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
@@ -41,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*
{@link InitializingBean} & {@link DisposableBean} interfaces
* Custom {@link RootBeanDefinition#getInitMethodName() init} &
* {@link RootBeanDefinition#getDestroyMethodName() destroy} methods
- * JSR 250's {@link javax.annotation.PostConstruct @PostConstruct} &
- * {@link javax.annotation.PreDestroy @PreDestroy} annotations
+ * JSR 250's {@link jakarta.annotation.PostConstruct @PostConstruct} &
+ * {@link jakarta.annotation.PreDestroy @PreDestroy} annotations
*
*
* @author Sam Brannen
@@ -173,7 +172,6 @@ class InitDestroyMethodLifecycleTests {
}
}
-
static class CustomInitDestroyBean {
final List initMethods = new ArrayList<>();
diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
deleted file mode 100644
index 821fffffcf..0000000000
--- a/spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright 2002-2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.context.annotation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import jakarta.annotation.PostConstruct;
-import jakarta.annotation.PreDestroy;
-import org.junit.jupiter.api.Test;
-
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.util.ObjectUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Unit test which verifies expected init and destroy
- * bean lifecycle behavior as requested in
- * SPR-3775.
- *
- * Specifically, combinations of the following are tested:
- *
- * - {@link InitializingBean} & {@link DisposableBean} interfaces
- * - Custom {@link RootBeanDefinition#getInitMethodName() init} &
- * {@link RootBeanDefinition#getDestroyMethodName() destroy} methods
- * - JSR 250's {@link jakarta.annotation.PostConstruct @PostConstruct} &
- * {@link jakarta.annotation.PreDestroy @PreDestroy} annotations
- *
- *
- * @author Sam Brannen
- * @since 2.5
- */
-public class Spr3775InitDestroyLifecycleTests {
-
- private static final String LIFECYCLE_TEST_BEAN = "lifecycleTestBean";
-
-
- private void assertMethodOrdering(String category, List expectedMethods, List actualMethods) {
- assertThat(ObjectUtils.nullSafeEquals(expectedMethods, actualMethods)).
- as("Verifying " + category + ": expected<" + expectedMethods + "> but got<" + actualMethods + ">.").isTrue();
- }
-
- private DefaultListableBeanFactory createBeanFactoryAndRegisterBean(
- Class> beanClass, String initMethodName, String destroyMethodName) {
-
- DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
- RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
- beanDefinition.setInitMethodName(initMethodName);
- beanDefinition.setDestroyMethodName(destroyMethodName);
- beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
- beanFactory.registerBeanDefinition(LIFECYCLE_TEST_BEAN, beanDefinition);
- return beanFactory;
- }
-
- @Test
- public void testInitDestroyMethods() {
- Class> beanClass = InitDestroyBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
- "afterPropertiesSet", "destroy");
- InitDestroyBean bean = (InitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods", Arrays.asList("afterPropertiesSet"), bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
- }
-
- @Test
- public void testInitializingDisposableInterfaces() {
- Class> beanClass = CustomInitializingDisposableBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
- "customDestroy");
- CustomInitializingDisposableBean bean = (CustomInitializingDisposableBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods", Arrays.asList("afterPropertiesSet", "customInit"),
- bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("destroy", "customDestroy"),
- bean.destroyMethods);
- }
-
- @Test
- public void testInitializingDisposableInterfacesWithShadowedMethods() {
- Class> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
- "afterPropertiesSet", "destroy");
- InitializingDisposableWithShadowedMethodsBean bean =
- (InitializingDisposableWithShadowedMethodsBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods", Arrays.asList("InitializingBean.afterPropertiesSet"),
- bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
- }
-
- @Test
- public void testJsr250Annotations() {
- Class> beanClass = CustomAnnotatedInitDestroyBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
- "customDestroy");
- CustomAnnotatedInitDestroyBean bean = (CustomAnnotatedInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods", Arrays.asList("postConstruct", "afterPropertiesSet",
- "customInit"), bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("preDestroy", "destroy", "customDestroy"),
- bean.destroyMethods);
- }
-
- @Test
- public void testJsr250AnnotationsWithShadowedMethods() {
- Class> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
- "customDestroy");
- CustomAnnotatedInitDestroyWithShadowedMethodsBean bean =
- (CustomAnnotatedInitDestroyWithShadowedMethodsBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods",
- Arrays.asList("@PostConstruct.afterPropertiesSet", "customInit"), bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("@PreDestroy.destroy", "customDestroy"),
- bean.destroyMethods);
- }
-
- @Test
- public void testAllLifecycleMechanismsAtOnce() {
- Class> beanClass = AllInOneBean.class;
- DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
- "afterPropertiesSet", "destroy");
- AllInOneBean bean = (AllInOneBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
- assertMethodOrdering("init-methods", Arrays.asList("afterPropertiesSet"), bean.initMethods);
- beanFactory.destroySingletons();
- assertMethodOrdering("destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
- }
-
-
- public static class InitDestroyBean {
-
- final List initMethods = new ArrayList<>();
- final List destroyMethods = new ArrayList<>();
-
- public void afterPropertiesSet() throws Exception {
- this.initMethods.add("afterPropertiesSet");
- }
-
- public void destroy() throws Exception {
- this.destroyMethods.add("destroy");
- }
- }
-
-
- public static class InitializingDisposableWithShadowedMethodsBean extends InitDestroyBean
- implements InitializingBean, DisposableBean {
-
- @Override
- public void afterPropertiesSet() throws Exception {
- this.initMethods.add("InitializingBean.afterPropertiesSet");
- }
-
- @Override
- public void destroy() throws Exception {
- this.destroyMethods.add("DisposableBean.destroy");
- }
- }
-
-
- public static class CustomInitDestroyBean {
-
- final List initMethods = new ArrayList<>();
- final List destroyMethods = new ArrayList<>();
-
- public void customInit() throws Exception {
- this.initMethods.add("customInit");
- }
-
- public void customDestroy() throws Exception {
- this.destroyMethods.add("customDestroy");
- }
- }
-
-
- public static class CustomInitializingDisposableBean extends CustomInitDestroyBean
- implements InitializingBean, DisposableBean {
-
- @Override
- public void afterPropertiesSet() throws Exception {
- this.initMethods.add("afterPropertiesSet");
- }
-
- @Override
- public void destroy() throws Exception {
- this.destroyMethods.add("destroy");
- }
- }
-
-
- public static class CustomAnnotatedInitDestroyBean extends CustomInitializingDisposableBean {
-
- @PostConstruct
- public void postConstruct() throws Exception {
- this.initMethods.add("postConstruct");
- }
-
- @PreDestroy
- public void preDestroy() throws Exception {
- this.destroyMethods.add("preDestroy");
- }
- }
-
-
- public static class CustomAnnotatedInitDestroyWithShadowedMethodsBean extends CustomInitializingDisposableBean {
-
- @PostConstruct
- @Override
- public void afterPropertiesSet() throws Exception {
- this.initMethods.add("@PostConstruct.afterPropertiesSet");
- }
-
- @PreDestroy
- @Override
- public void destroy() throws Exception {
- this.destroyMethods.add("@PreDestroy.destroy");
- }
- }
-
-
- public static class AllInOneBean implements InitializingBean, DisposableBean {
-
- final List initMethods = new ArrayList<>();
- final List destroyMethods = new ArrayList<>();
-
- @PostConstruct
- @Override
- public void afterPropertiesSet() throws Exception {
- this.initMethods.add("afterPropertiesSet");
- }
-
- @PreDestroy
- @Override
- public void destroy() throws Exception {
- this.destroyMethods.add("destroy");
- }
- }
-
-}