I have a data project and a user interface project. Both projects are Spring boot applications. Both projects have the same root package (com.myorg) with the main class annotated with @SpringBootApplication .
The main class of the data project:
package com.myorg; @SpringBootApplication public class DataApplication { public static void main(String[] args) { SpringApplication.run(DataApplication.class, args); } }
The main class of the interface project:
package com.myorg; @SpringBootApplication public class UiApplication { public static void main(String[] args) { SpringApplication.run(UiApplication .class, args); } }
The user interface design depends on the data design through the following Gradle dependency:
dependencies { compile('com.myorg:data:1.0') }
If I run the user interface application, it starts without problems. However, if I run an integration test in a user interface application, for example:
package com.myorg @RunWith(SpringRunner.class) @SpringBootTest public class UiIntTest { @Test public void contextLoads() { } }
The following initialization error occurred:
java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes
In the main data project class, if I replaced @SpringBootApplication with
@Configuration @EnableAutoConfiguration @ComponentScan({ "com.myorg" })
When I try to run integration tests, I get the following initialization error:
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
For example, if I try to run:
package com.myorg @RunWith(SpringRunner.class) @SpringBootTest public class DataIntTest { @Test public void contextLoads() { } }
How to set up data projects and user interfaces?