【发布时间】:2022-01-15 21:52:10
【问题描述】:
这是我的问题——我有一项依赖于外部库的服务。我试图自动连接服务,以便我可以使用它但无法
import org.keycloak.admin.client.token.TokenService;
public class SimpleService {
@Autowired
private TokenService keycloakTokenSvc; // Could not autowire, no beans of type 'TokenService' found
public void execute() {
keyCloakTokenSvc.doSomething();
}
}
然后我将它添加到我的 SpringBootApplication 并让它工作:
@SpringBootApplication
@ComponentScan({"org.keycloak.admin.client.token"})
public MyApp {}
甜蜜——现在一切都好,对吧?没有。这似乎覆盖了我的一些自动配置,比如我的安全配置,所以我不再在我的应用程序运行时向它发出 RESTful 请求。然后我接下来做了这个:
@SpringBootApplication
@ComponentScan({"org.keycloak.admin.client.token", "com.project.pkg"})
public MyApp {}
还是什么都没有。我得到和以前一样的错误:
Field keycloakTokenSvc in com.mark43.jms.services.TokenRefreshService required a bean of type 'org.keycloak.admin.client.token.TokenService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.keycloak.admin.client.token.TokenService' in your configuration.
我是 Spring Boot 的新手,所以不知道在这里做什么。有没有办法在没有自动装配的情况下使用TokenService?有没有办法扫描两个包?
【问题讨论】:
-
这是我项目之外的一个包,我不能注释它。您只能使用带注释的服务吗?
标签: spring spring-boot keycloak