{"action":"closed","issue":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4426","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4426/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4426/comments","events_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4426/events","html_url":"https://github.com/spring-projects/spring-boot/issues/4426","id":116228590,"number":4426,"title":"Disable Spring Starter JPA/Hibernate for Unit test","user":{"login":"nsdiv","id":2092911,"avatar_url":"https://avatars.githubusercontent.com/u/2092911?v=3","gravatar_id":"","url":"https://api.github.com/users/nsdiv","html_url":"https://github.com/nsdiv","followers_url":"https://api.github.com/users/nsdiv/followers","following_url":"https://api.github.com/users/nsdiv/following{/other_user}","gists_url":"https://api.github.com/users/nsdiv/gists{/gist_id}","starred_url":"https://api.github.com/users/nsdiv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsdiv/subscriptions","organizations_url":"https://api.github.com/users/nsdiv/orgs","repos_url":"https://api.github.com/users/nsdiv/repos","events_url":"https://api.github.com/users/nsdiv/events{/privacy}","received_events_url":"https://api.github.com/users/nsdiv/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-10T23:44:52Z","updated_at":"2015-11-10T23:59:16Z","closed_at":"2015-11-10T23:59:16Z","body":"While running a unit test that tests our service layer, connecting to a database, even if it is an embedded one, is unnecessary. It is easier to just mock out all the beans.\r\nI was able to do that successfully for spring boot Mongo. Here is the gist:\r\nhttps://gist.github.com/nsdiv/9effb78e27ff6ca94381\r\n\r\nHowever I am not able to do it for spring boot JPA/Hibernate. Here are the beans I'm mocking \r\n\r\n```java    \r\n    @Bean\r\n    public DataSource dataSource() {\r\n        return null;\r\n    }\r\n\r\n    @Bean\r\n    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {\r\n        return null;\r\n    }\r\n\r\n    @Bean\r\n    public JpaVendorAdapter jpaVendorAdapter() {\r\n        return null;\r\n    }\r\n\r\n    @Bean\r\n    public NamedParameterJdbcTemplate mySqlJdbcTemplate(DataSource dataSource) {\r\n        return null;\r\n    }\r\n```\r\n\r\nHowever I get an NPE while creating a bean. On setting loglevel to DEBUG, the following is printed.\r\n\r\n```\r\n2015-11-10 15:24:26,739; thread=[main]; LogLevel=DEBUG; category=org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer; msg=\r\n\r\n\r\n=========================\r\nAUTO-CONFIGURATION REPORT\r\n=========================\r\nPositive matches:\r\n-----------------\r\n  AopAutoConfiguration\r\n      - @ConditionalOnClass classes found: org.springframework.context.annotation.EnableAspectJAutoProxy,org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)\r\n      - matched (OnPropertyCondition)\r\n\r\n   AopAutoConfiguration.JdkDynamicAutoProxyConfiguration\r\n      - matched (OnPropertyCondition)\r\n\r\n   ArchaiusAutoConfiguration\r\n      - @ConditionalOnClass classes found: com.netflix.config.ConcurrentCompositeConfiguration,org.apache.commons.configuration.ConfigurationBuilder (OnClassCondition)\r\n\r\n   ArchaiusAutoConfiguration.ArchaiusEndpointConfiguration\r\n      - @ConditionalOnClass classes found: org.springframework.boot.actuate.endpoint.Endpoint (OnClassCondition)\r\n\r\n   ArchaiusAutoConfiguration.PropagateEventsConfiguration\r\n      - @ConditionalOnClass classes found: org.springframework.cloud.context.environment.EnvironmentChangeEvent (OnClassCondition)\r\n      - matched (OnPropertyCondition)\r\n\r\n   AuditAutoConfiguration#authenticationAuditListener\r\n      - @ConditionalOnClass classes found: org.springframework.security.authentication.event.AbstractAuthenticationEvent (OnClassCondition)\r\n\r\n   AuditAutoConfiguration#authorizationAuditListener\r\n      - @ConditionalOnClass classes found: org.springframework.security.access.event.AbstractAuthorizationEvent (OnClassCondition)\r\n\r\n   AuditAutoConfiguration.AuditEventRepositoryConfiguration\r\n      - @ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; SearchStrategy: all) found no beans (OnBeanCondition)\r\n\r\n   BootGlobalAuthenticationConfiguration\r\n      - @ConditionalOnClass classes found: org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter (OnClassCondition)\r\n\r\n   DataSourceAutoConfiguration\r\n      - @ConditionalOnClass classes found: javax.sql.DataSource,org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)\r\n\r\n   DataSourceAutoConfiguration.DataSourceInitializerConfiguration\r\n      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) found no beans (OnBeanCondition)\r\n\r\n   DataSourceAutoConfiguration.JdbcTemplateConfiguration\r\n      - existing auto database detected (DataSourceAutoConfiguration.DataSourceAvailableCondition)\r\n      - existing bean configured database detected (DataSourceAutoConfiguration.DataSourceAvailableCondition)\r\n\r\n   DataSourceAutoConfiguration.JdbcTemplateConfiguration#jdbcTemplate\r\n      - @ConditionalOnMissingBean (types: org.springframework.jdbc.core.JdbcOperations; SearchStrategy: all) found no beans (OnBeanCondition)\r\n\r\n   DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration\r\n      - @ConditionalOnClass classes found: org.apache.tomcat.jdbc.pool.DataSource (OnClassCondition)\r\n\r\n   DataSourceTransactionManagerAutoConfiguration\r\n      - @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)\r\n\r\n   DataSourceTransactionManagerAutoConfiguration.TransactionManagementConfiguration\r\n      - @ConditionalOnMissingBean (types: org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; SearchStrategy: all) found no beans (OnBeanCondition)\r\n\r\n   .............\r\n.....\r\n.....\r\n\r\n2015-11-10 15:24:26,745; thread=[main]; LogLevel=ERROR; category=org.springframework.boot.SpringApplication; msg=Application startup failed; \r\njava.lang.NullPointerException: null\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1501) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:314) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:960) ~[spring-context-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:749) ~[spring-context-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689) ~[spring-boot-1.2.7.RELEASE.jar:1.2.7.RELEASE]\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:321) ~[spring-boot-1.2.7.RELEASE.jar:1.2.7.RELEASE]\r\n\tat org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:103) [spring-boot-1.2.7.RELEASE.jar:1.2.7.RELEASE]\r\n\tat org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212) [spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]\r\n\tat \r\n```"}}