Reputation: 357
I have a multi project gradle project:
ht-java
ht-scraper uses the domain model and daos which are located in ht-domain. when i start the springboot app i get the following error:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.hypetube.domain.dao.ChannelRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
when i have the repository classes within ht-scraper everything works fine.
my spring app looks like this:
@Configuration
@EnableAutoConfiguration
@ComponentScan({"com.hypetube", "com.hypetube.domain"})
@EnableConfigurationProperties //use this to register other properties sources e.g. property files
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Autowired
private Environment env;
@PostConstruct
public void printActiveSpringProfiles() {
log.info("Following spring profiles are active: {}", new ArrayList<>(Arrays.asList(env.getActiveProfiles())));
}
}
settings.gradle:
include 'ht-domain', 'ht-scraper'
build.gradle (ht.scraper):
compile project(":ht-domain")
Everything works as it should; The project compiles no errors are imminent. Just when i start the app the error occurs.
Upvotes: 2
Views: 2314
Reputation: 84844
It's very strange why spring-boot
plugin doesn't include the ht-domain
subproject. To workaround tests add the following piece of code to ht-scraper/build.gradle
test {
classpath = project(":ht-domain").sourceSets.main.runtimeClasspath
}
But there's still problem with running packaged application. I've removed all the annotations from PlaylistRepository
class and added the following annotation to Application
:
@EnableMongoRepositories({"com.hypetube.domain"})
No it starts well - at least there're no classpath issues. Hope that helps somehow and as I said quite weird behavior :/
Upvotes: 1