|
22 | 22 | import org.junit.Rule;
|
23 | 23 | import org.junit.Test;
|
24 | 24 | import org.junit.rules.ExpectedException;
|
| 25 | +import org.springframework.beans.BeansException; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; |
| 27 | +import org.springframework.beans.factory.config.BeanPostProcessor; |
25 | 28 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
26 | 29 | import org.springframework.context.annotation.Bean;
|
27 | 30 | import org.springframework.context.annotation.Configuration;
|
@@ -99,6 +102,13 @@ public void needsEntityManageFactory() throws Exception {
|
99 | 102 | this.context = new AnnotationConfigApplicationContext(MissingEntityManager.class);
|
100 | 103 | }
|
101 | 104 |
|
| 105 | + @Test |
| 106 | + public void userDeclaredBeanPostProcessorWithEntityManagerDependencyDoesNotPreventConfigurationOfPackagesToScan() { |
| 107 | + this.context = new AnnotationConfigApplicationContext( |
| 108 | + BeanPostProcessorConfiguration.class, BaseConfig.class); |
| 109 | + assertSetPackagesToScan("com.mycorp.entity"); |
| 110 | + } |
| 111 | + |
102 | 112 | private void assertSetPackagesToScan(String... expected) {
|
103 | 113 | String[] actual = this.context.getBean(
|
104 | 114 | TestLocalContainerEntityManagerFactoryBean.class).getPackagesToScan();
|
@@ -148,6 +158,33 @@ static class BasePackagesAndBasePackageClasses extends BaseConfig {
|
148 | 158 | static class MissingEntityManager {
|
149 | 159 | }
|
150 | 160 |
|
| 161 | + @Configuration |
| 162 | + @EntityScan("com.mycorp.entity") |
| 163 | + static class BeanPostProcessorConfiguration { |
| 164 | + |
| 165 | + @Autowired |
| 166 | + private EntityManagerFactory entityManagerFactory; |
| 167 | + |
| 168 | + @Bean |
| 169 | + public BeanPostProcessor beanPostProcessor() { |
| 170 | + return new BeanPostProcessor() { |
| 171 | + |
| 172 | + @Override |
| 173 | + public Object postProcessBeforeInitialization(Object bean, String beanName) |
| 174 | + throws BeansException { |
| 175 | + return bean; |
| 176 | + } |
| 177 | + |
| 178 | + @Override |
| 179 | + public Object postProcessAfterInitialization(Object bean, String beanName) |
| 180 | + throws BeansException { |
| 181 | + return bean; |
| 182 | + } |
| 183 | + }; |
| 184 | + |
| 185 | + } |
| 186 | + } |
| 187 | + |
151 | 188 | private static class TestLocalContainerEntityManagerFactoryBean extends
|
152 | 189 | LocalContainerEntityManagerFactoryBean {
|
153 | 190 |
|
|
0 commit comments