我有一个多项目gradle项目:
ht-java
- ht-domain
- ht-scraper
ht-scraper使用域模型和daos它们位于ht域。
当我启动springboot应用程序时,出现以下错误:
org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到符合条件的[com.hypetube.domain.dao.ChannelRepository]类型的符合条件的Bean:期望至少1个符合此依赖关系自动装配候选资格的bean。依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
当我有ht-scraper中的存储库类时,一切正常。
我的spring应用程序如下所示:
@Configuration
@EnableAutoConfiguration
@ComponentScan({com.hypetube,com.hypetube.domain})
@EnableConfigurationProperties //使用它来注册其他属性来源,例如属性文件
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环境env;
@PostConstruct $ b $ public void printActiveSpringProfiles(){
log.info(以下春季配置文件处于活动状态:{},new ArrayList<>(Arrays.asList(env .getActiveProfiles())));
settings.gradle:
包括'ht-domain','ht-scraper'
build.gradle(ht.scraper):
compile project(:ht-domain )
一切正常,该项目编译没有错误即将发生。
只是当我启动应用程序时出现错误。
很奇怪为什么 spring -boot
插件不包含 ht-domain
子项目。要解决方法测试,请将以下代码添加到 ht-scraper / build.gradle
test {
classpath = project(:ht-domain)。sourceSets.main.runtimeClasspath
}
但运行打包应用程序仍然存在问题。我从 PlaylistRepository
类中删除了所有注释,并将以下注释添加到 Application
:
@EnableMongoRepositories({com.hypetube.domain})
不,它开始顺利 - 至少没有类路径问题。希望这有助于某种方式,正如我所说的很奇怪的行为:/ $ /
I have a multi project gradle project:
ht-java
- ht-domain
- ht-scraper
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.
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 :/
这篇关于在gradle子项目中找不到Spring资源库组件(Springboot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!