Issue
I've a spring-boot
project with spring-boot-starter-web
and spring-boot-starter-data
dependencies in classpath.
compile "org.springframework.boot:spring-boot-starter-web:1.0.2.RELEASE"
compile "org.springframework.boot:spring-boot-starter-data-jpa:1.0.2.RELEASE"
Now, I want to test only spring-data-jpa
related classes. For that I want spring-boot
to do auto configuration for spring-boot-starter-data-jpa
only. However, if I do @EnableAutoConfiguration
in @Configuation
class used for testing, spring-boot
tries to auto-configure for both spring-boot-starter-web
and spring-boot-starter-data-jpa
.
@SpringApplicationConfiguration(classes = {DataConfig.class})
public class PersonRepositoryTests extends AbstractJUnit4SpringContextTests {
@Autowired
PersonRepository personRepository;
@Test
public void testSaveWithNameNull() {
/* ... */
}
}
@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(basePackageClasses = {RepoPackage.class})
@EntityScan(basePackageClasses = {DomainPackage.class})
@EnableTransactionManagement
public class DataConfig {
}
How can spring boot be configured so that it auto-configure for specific dependencies only for testing purposes?
In my context, I want spring-boot
to auto-configure only spring-data-jpa
related configurations omitting web
related configurations.
Or, Is there any other better way to setup this type of test configuration in spring-boot?
Solution
I think you already have it. If you use @SpringApplicationConfiguration
and don't specify @WebAppConcfiguration
then you don't get a webapp and hence there is no MVC layer.
Answered By - Dave Syer
Answer Checked By - Robin (JavaFixing Admin)