commit
						45915d085e
					
				|  | @ -53,15 +53,34 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||
|  * @author Vince Bickers | ||||
|  * @author Stephane Nicoll | ||||
|  * @author Kazuki Shimizu | ||||
|  * @author Michael Simons | ||||
|  * @since 1.4.0 | ||||
|  */ | ||||
| @Configuration(proxyBeanMethods = false) | ||||
| @ConditionalOnClass({ SessionFactory.class, Neo4jTransactionManager.class, PlatformTransactionManager.class }) | ||||
| @ConditionalOnMissingBean(SessionFactory.class) | ||||
| @EnableConfigurationProperties(Neo4jProperties.class) | ||||
| @Import(Neo4jBookmarkManagementConfiguration.class) | ||||
| public class Neo4jDataAutoConfiguration { | ||||
| 
 | ||||
| 	@Bean | ||||
| 	@ConditionalOnMissingBean(PlatformTransactionManager.class) | ||||
| 	public Neo4jTransactionManager transactionManager(SessionFactory sessionFactory, | ||||
| 			ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) { | ||||
| 		return customize(new Neo4jTransactionManager(sessionFactory), transactionManagerCustomizers.getIfAvailable()); | ||||
| 	} | ||||
| 
 | ||||
| 	private Neo4jTransactionManager customize(Neo4jTransactionManager transactionManager, | ||||
| 			TransactionManagerCustomizers customizers) { | ||||
| 		if (customizers != null) { | ||||
| 			customizers.customize(transactionManager); | ||||
| 		} | ||||
| 		return transactionManager; | ||||
| 	} | ||||
| 
 | ||||
| 	@Configuration(proxyBeanMethods = false) | ||||
| 	@ConditionalOnMissingBean(SessionFactory.class) | ||||
| 	protected static class Neo4jOgmSessionFactoryConfiguration { | ||||
| 
 | ||||
| 		@Bean | ||||
| 		@ConditionalOnMissingBean | ||||
| 		public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) { | ||||
|  | @ -76,21 +95,6 @@ public class Neo4jDataAutoConfiguration { | |||
| 			return sessionFactory; | ||||
| 		} | ||||
| 
 | ||||
| 	@Bean | ||||
| 	@ConditionalOnMissingBean(PlatformTransactionManager.class) | ||||
| 	public Neo4jTransactionManager transactionManager(SessionFactory sessionFactory, Neo4jProperties properties, | ||||
| 			ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) { | ||||
| 		return customize(new Neo4jTransactionManager(sessionFactory), transactionManagerCustomizers.getIfAvailable()); | ||||
| 	} | ||||
| 
 | ||||
| 	private Neo4jTransactionManager customize(Neo4jTransactionManager transactionManager, | ||||
| 			TransactionManagerCustomizers customizers) { | ||||
| 		if (customizers != null) { | ||||
| 			customizers.customize(transactionManager); | ||||
| 		} | ||||
| 		return transactionManager; | ||||
| 	} | ||||
| 
 | ||||
| 		private String[] getPackagesToScan(ApplicationContext applicationContext) { | ||||
| 			List<String> packages = EntityScanPackages.get(applicationContext).getPackageNames(); | ||||
| 			if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) { | ||||
|  | @ -99,6 +103,8 @@ public class Neo4jDataAutoConfiguration { | |||
| 			return StringUtils.toStringArray(packages); | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Configuration(proxyBeanMethods = false) | ||||
| 	@ConditionalOnWebApplication(type = Type.SERVLET) | ||||
| 	@ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class }) | ||||
|  |  | |||
|  | @ -99,6 +99,16 @@ class Neo4jDataAutoConfigurationTests { | |||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	void customSessionFactoryShouldNotDisableOtherDefaults() { | ||||
| 		this.contextRunner.withUserConfiguration(CustomSessionFactory.class).run((context) -> { | ||||
| 			assertThat(context).hasSingleBean(SessionFactory.class); | ||||
| 			assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory")); | ||||
| 			assertThat(context).hasSingleBean(Neo4jTransactionManager.class); | ||||
| 			assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class); | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	void customConfiguration() { | ||||
| 		this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> { | ||||
|  |  | |||
|  | @ -4667,9 +4667,9 @@ properties, as shown in the following example: | |||
| 	spring.data.neo4j.password=secret | ||||
| ---- | ||||
| 
 | ||||
| You can take full control over the session creation by adding a | ||||
| `org.neo4j.ogm.config.Configuration` `@Bean`. Also, adding a `@Bean` of type | ||||
| `SessionFactory` disables the auto-configuration and gives you full control. | ||||
| You can take full control over the session creation by either adding a | ||||
| `org.neo4j.ogm.config.Configuration` bean or a `org.neo4j.ogm.session.SessionFactory` | ||||
| bean. | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue