Reputation: 8015
This may seem like a trivial problem but I have spent several hours trying to solve this so I would be glad for any help and insight on what is going on.
I have two Spring-boot maven projects in Eclipse. Lets call them ProjectA and ProjectB. I need to use one class (POJO) from ProjectA in ProjectB. That means ProjectA is a dependency of ProjectB.
I put this dependency in ProjectB's pom.xml:
<dependency>
<groupId>cz.my.project</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
In Eclipse, everything seems fine but when I launch Tomcat with ProjectB, I get all sorts of exceptions (depending on the scope I set for this dependency).
I either get ClassNotFound exception for the class that I am trying to use from ProjectA, or I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration
ProjectA contains a Flyway with some migration scripts which are somehow being executed in ProjectB (even though ProjectB does not contain any Flyway stuff).
When running maven compile, I get the following exception (its searching the central repo instead of the local one):
Could not resolve dependencies for project cz.ProjectA.MyPOJO-service:war:0.0.1: Could not find artifact cz.ProjectA:jar:0.0.1 in central (http://repo.maven.apache.org/maven2)
Can anyone help me with solving this issue? I tried all sorts of things: putting the projectA on classpath manually, running maven install on ProjectA, putting these two projects in the same working set etc.. Nothing worked so far.
Upvotes: 1
Views: 3107
Reputation: 9490
If you import a Spring Boot project in that way, you're importing all of the @Configuration
classes and Spring Boot will perform scanning of everything you have in there in order to wire it up automatically.
The best way of resolving this is to create a separate project containing classes which are used by both projects and import that.
However, there are a couple of ways in which you can probably get this working.
First, although I'm not sure about how Flyway gets configured, but if it is done in one of your @Configuration
classes, then you could annotated that configuration with @Profile("flyway")
. That way, if a project needs Flyway migrations to run, then it can activate the profile. Otherwise, Flyway doesn't get activated.
Second, if the auto configuration is not in your project (as in many of the Spring Boot Starter dependencies), then you could exclude whatever @Configuration
class auto-wires Flyway by putting this in your Spring Boot application class (well ... any @Configuration
really):
@EnableAutoConfiguration(exclude = { FlywayConfiguration.class })
... where FlywayConfiguration.class
is the class which does the auto-wiring, whether that's in your project or an imported third party library. I use this sometimes to disable security auto-configuration for tests.
I'm sure there are a few more options, but I think those are your best bets.
Upvotes: 1