在具有反应性并使用jwt的spring boot应用程序中,在我的spring-cloud-gateway中,我有此代码。
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayServiceApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServiceApplication.class, args);
}
}
@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class SpringSecurityWebFluxConfig {
private final UserServiceImpl userService;
private final JwtTokenUtil tokenUtil;
private static final String[] AUTH_WHITELIST = {
"/resources/**",
"/webjars/**",
"/authorize/**",
"/favicon.ico"};
public SpringSecurityWebFluxConfig(JwtTokenUtil tokenUtil, UserServiceImpl userService) {
this.tokenUtil = tokenUtil;
this.userService = userService;
}
..
}
@Service
public class UserServiceImpl implements ReactiveUserDetailsService, UserService {
private final UserRepository userRepository;
public UserServiceImpl(final UserRepository userRepository) {
this.userRepository = userRepository;
}
...
}
@Repository
public interface UserRepository extends ReactiveCrudRepository<User, Integer>{
}
public class JWTHeadersExchangeMatcher implements ServerWebExchangeMatcher {
@Override
public Mono<MatchResult> matches(final ServerWebExchange exchange) {
}
}
public class JWTReactiveAuthenticationManager implements ReactiveAuthenticationManager {
...
public JWTReactiveAuthenticationManager(final PasswordEncoder passwordEncoder, final UserServiceImpl userService) {
this.passwordEncoder = passwordEncoder;
this.userService = userService;
}
}
public class JwtTokenUtil {
...
}
public class TokenAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {
private final JwtTokenUtil tokenProvider;
public TokenAuthenticationConverter(JwtTokenUtil tokenProvider) {
this.tokenProvider = tokenProvider;
}
}
public class TokenAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {
private final JwtTokenUtil tokenProvider;
public TokenAuthenticationConverter(JwtTokenUtil tokenProvider) {
this.tokenProvider = tokenProvider;
}
}
- [main] onfigReactiveWebServerApplicationContext:上下文初始化期间遇到异常-取消 刷新尝试: org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为“ springSecurityWebFluxConfig”的bean时出错 文件 [/home/mac/Development/project/reactive-cloud/gateway-service/build/classes/java/main/com/example/gatewayservice/config/SpringSecurityWebFluxConfig.class]: 通过构造函数参数1表示的不满意依赖性; 嵌套异常为 org.springframework.beans.factory.UnsatisfiedDependencyException: 在文件中定义名称为“ userServiceImpl”的bean创建时出错 [/home/mac/Development/project/reactive-cloud/gateway-service/build/classes/java/main/com/example/gatewayservice/service/UserServiceImpl.class]: 通过构造函数参数0表示的不满足的依赖关系; 嵌套异常为 org.springframework.beans.factory.NoSuchBeanDefinitionException:否 类型的合格豆 可用的“ com.example.gatewayservice.repository.UserRepository”: 期望至少有1个符合自动装配候选条件的bean。 依赖注释:{} 2019-06-27 11:47:23.336 INFO 53073 --- [
main] ConditionEvaluationReportLoggingListener:
试图将其自动接线
在SpringSecurityWebFluxConfig类中的UserServiceImpl上
在UserServiceImpl类的UserRepository上
在JWTReactiveAuthenticationManager.class的UserServiceImpl上
但出现相同错误
编辑
如果我使用
@ EnableR2dbcRepositories到GatewayServiceApplication,我没有此错误,但它搜索有关DatabaseClient的信息
答案 0 :(得分:0)
请在UserServiceImpl类中为构造函数或变量级别中的UserRepository变量添加@Autowired注释。