I've Project A with the following specs:
- Jar
- Java 7
- Spring 4.2.0 + Spring Security
- Spring Data JPA, Oracle, H2 (w/ scope test)
I've Project B with the following specs:
- War
- Java 8
- Tomcat 8.5.x
- Spring Boot 2
- Spring 5 + Spring Security
Both projects successfully build and run individually. I want Project A be a dependency of Project B. I'm using IntelliJ and followed steps available on the web (#1, #2), but here's the gist of what I did:
File -> Project Structure
- Project -> Ensure Project A's SDK + Project level are set to Java 8
- Modules -> Select Project A -> Ensure SDK + Project level are set to Java 8 for Sources + Dependencies
- Modules -> Click + button > Import Module -> Select Project A's pom.xml -> Follow import steps
- Modules -> Select Project B -> Ensure SDK + Project level are set to Java 8 for Sources + Dependencies
- Modules -> Select Project A -> Dependencies -> Click + button > Add Module Dependency -> Select Project A
- Add Project A as dependency into Project B's pom.xml, and match dependency's version with Project A's version (from pom)
I successfully run "mvn clean install". When I run Project B on Tomcat, I get:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-08-14 15:01:03.796 ERROR 15888 --- [on(3)-127.0.0.1] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
I'm not sure why Project A's JPA/DB config is causing issues in Project B, even though Project A works fine by itself. But, after some research, I added the following annotation to my SpringBoot Application:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
and this is what I ended up with:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class ProjectB extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ProjectB.class);
}
public static void main(String[] args) {
SpringApplication.run(ProjectB.class, args);
}
}
I successfully run "mvn clean install". I run Project B again, and it launches successfully! when I try to reference anything from Project A (i.e. A service), it builds fine, but when launching I get the following:
SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
***************************
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
APPLICATION FAILED TO START
***************************
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1736)
Description:
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Parameter 0 of constructor in com.projectB.controller.ControllerName required a bean of type 'com.projecta.service.ServiceName' that could not be found.
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
Action:
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
Consider defining a bean of type 'com.projecta.service.ServiceName' in your configuration.
Is it even possible to import Spring module into Spring Boot 2? If so, what am I missing? If not, what're my options?
Edit 1: Add Simple service (Project A) + controller (Project B)
// Controller in Project B
@RestController
@RequestMapping("/api")
public class SimpleController {
private SimpleService simpleService;
@Autowired
public SimpleController(SimpleService simpleService) {
this.simpleService = simpleService;
}
@GetMapping
public ResponseEntity<?> generateAndSendEmail() {
boolean success = simpleService.callSimpleService();
if (success) {
return new ResponseEntity<>(OK);
}
return new ResponseEntity<>(INTERNAL_SERVER_ERROR);
}
}
// Service in Project A
@Service
public class SimpleService {
public boolean callSimpleService() {
return true;
}
}