mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Remember to add interceptor to registry
This commit is contained in:
parent
f52d624be5
commit
eba5b74910
@ -54,8 +54,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EnableTransactionManagement.class,
|
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class,
|
||||||
EntityManager.class })
|
EnableTransactionManagement.class, EntityManager.class })
|
||||||
@ConditionalOnBean(DataSource.class)
|
@ConditionalOnBean(DataSource.class)
|
||||||
public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||||
|
|
||||||
@ -78,13 +78,14 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class, OpenEntityManagerInViewFilter.class })
|
@ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class,
|
||||||
|
OpenEntityManagerInViewFilter.class })
|
||||||
@ConditionalOnExpression("${spring.jpa.openInView:${spring.jpa.open_in_view:true}}")
|
@ConditionalOnExpression("${spring.jpa.openInView:${spring.jpa.open_in_view:true}}")
|
||||||
protected static class JpaWebConfiguration extends WebMvcConfigurerAdapter {
|
protected static class JpaWebConfiguration extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
super.addInterceptors(registry);
|
registry.addWebRequestInterceptor(openEntityManagerInViewInterceptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -95,14 +96,18 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the {@code dataSource} being used by Spring was created from {@link EmbeddedDatabaseConfiguration}.
|
* Determines if the {@code dataSource} being used by Spring was created from
|
||||||
|
* {@link EmbeddedDatabaseConfiguration}.
|
||||||
* @return true if the data source was auto-configured.
|
* @return true if the data source was auto-configured.
|
||||||
*/
|
*/
|
||||||
protected boolean isAutoConfiguredDataSource() {
|
protected boolean isAutoConfiguredDataSource() {
|
||||||
try {
|
try {
|
||||||
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("dataSource");
|
BeanDefinition beanDefinition = this.beanFactory
|
||||||
return EmbeddedDatabaseConfiguration.class.getName().equals(beanDefinition.getFactoryBeanName());
|
.getBeanDefinition("dataSource");
|
||||||
} catch (NoSuchBeanDefinitionException ex) {
|
return EmbeddedDatabaseConfiguration.class.getName().equals(
|
||||||
|
beanDefinition.getFactoryBeanName());
|
||||||
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,19 +118,23 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||||||
protected DataSource getDataSource() {
|
protected DataSource getDataSource() {
|
||||||
try {
|
try {
|
||||||
return this.beanFactory.getBean("dataSource", DataSource.class);
|
return this.beanFactory.getBean("dataSource", DataSource.class);
|
||||||
} catch (RuntimeException ex) {
|
}
|
||||||
|
catch (RuntimeException ex) {
|
||||||
return this.beanFactory.getBean(DataSource.class);
|
return this.beanFactory.getBean(DataSource.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getPackagesToScan() {
|
protected String[] getPackagesToScan() {
|
||||||
List<String> basePackages = AutoConfigurationUtils.getBasePackages(this.beanFactory);
|
List<String> basePackages = AutoConfigurationUtils
|
||||||
Assert.notEmpty(basePackages, "Unable to find JPA packages to scan, please define "
|
.getBasePackages(this.beanFactory);
|
||||||
+ "a @ComponentScan annotation or disable JpaAutoConfiguration");
|
Assert.notEmpty(basePackages,
|
||||||
|
"Unable to find JPA packages to scan, please define "
|
||||||
|
+ "a @ComponentScan annotation or disable JpaAutoConfiguration");
|
||||||
return basePackages.toArray(new String[basePackages.size()]);
|
return basePackages.toArray(new String[basePackages.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configure(LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
|
protected void configure(
|
||||||
|
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user