我很努力从自定义库中自动导入bean,导入的是gradle。 阅读了几个类似的话题后,我仍然无法找到解决方案。Spring Boot:从图书馆项目中自动导入bean
我有Spring Boot项目,依赖于其他项目(我的自定义库与组件,存储库等...)。这个库是一个Spring不可运行的jar,主要由域Entities和Repositories组成。它没有可运行的Application.class和任何属性...
当我启动应用程序时,我可以看到我的'CustomUserService'bean(来自库)试图初始化,但自动装入的bean加载失败(接口UserRepository)...
错误:
Parameter 0 of constructor in com.myProject.customLibrary.configuration.CustomUserDetailsService required a bean of type 'com.myProject.customLibrary.configuration.UserRepository' that could not be found.
我甚至试图设置“订单”,到(与“scanBasePackageClasses”)显式装载它,使用包和标记扫描类,添加额外的'EnableJPARepository'注释,但没有任何作品...
代码示例(软件包的名称已更改为简单起见)
package runnableProject.application;
import runnableProject.application.configuration.ServerConfigurationReference.class
import com.myProject.customLibrary.SharedReference.class
//@SpringBootApplication(scanBasePackages = {"com.myProject.customLibrary", "runnableProject.configuration"})
//@EnableJpaRepositories("com.myProject.customLibrary")
@SpringBootApplication(scanBasePackageClasses = {SharedReference.class, ServerConfigurationReference.class})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
类从库:
package com.myProject.customLibrary.configuration;
import com.myProject.customLibrary.configuration.UserRepository.class;
@Service
public class CustomUserDetailsService implements UserDetailsService {
private UserRepository userRepository;
@Autowired
public CustomUserDetailsService(UserRepository userRepository) {
this.userRepository = userRepository;
}
...
package myProject.customLibrary.configuration;
@Repository
public interface UserRepository extends CustomRepository<User> {
User findByLoginAndStatus(String var1, Status var2);
...
}
您可以接受你自己的答案! – alexbt
是的。该系统将允许我在2天内完成。 – maret
2天已过。你值得得分。搜索一大堆网站后,你的答案解决了我的问题。 – mvallebr