Comments (1)
最近在学习这个项目中的Spring Security,用其中的代码做了一个自己的项目,在线下用
mvn package
和java -jar
都运行正常,使用DevOps部署到线上出现了循环依赖的异常。(为了使idea生成下面的图,加了几处@Autowired
注解)
要生成
userController
,就需要通过自动装配方式使用userService
public class UserController { private final UserService userService;其中
userService
需要bCryptPasswordEncoder
,也是通过@Autowired
方式装配public class UserService { @Autowired private final BCryptPasswordEncoder bCryptPasswordEncoder;
bCryptPasswordEncoder
从securityConfig
中由注解@Bean
制造出public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public BCryptPasswordEncoder bCryptPasswordEncoder() { return new BCryptPasswordEncoder(); }在此之前,
securityConfig
需要得到userDetailsServiceImpl
public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired UserDetailsServiceImpl userDetailsServiceImpl;
userDetailsServiceImpl
又需要使用userService
来调用它的find
方法@Service public class UserDetailsServiceImpl implements UserDetailsService { private final UserService userService; @Autowired public UserDetailsServiceImpl(UserService userService) { this.userService = userService; } @Override public UserDetails loadUserByUsername(String name) { User user = userService.find(name); return new JwtUser(user); } }但此时的
userService
还没有制造好……于是有了循环依赖异常org.springframework.beans.factory.UnsatisfiedDependencyException
-->UnsatisfiedDependencyException
--> ... -->beans.factory.BeanCurrentlyInCreationException
通过改写
loadUserByUsername
的方式,去除了UserDetailsServiceImpl
对UserService
的依赖,临时性地解决了这个异常。
不好意思 ,刚看到。我目前把登录接口暴露出去,这个问题也没有了。
from spring-security-jwt-guide.
Related Issues (20)
- 认证服务器、资源服务器、客户端
- 怎么里面的类,跟示例的不一样? HOT 1
- 为啥没有看到 auth/login 这个路由定义在哪个控制器了呢? HOT 1
- "/auth/register"未定义解决
- 登录URL的问题 HOT 1
- User实体里的updateFrom方法未给密码加密导致更新后以明文存储密码 HOT 1
- 说明文档请修改一下 HOT 2
- 前端访问产生cors问题 HOT 2
- 按照你的方式自行搭建了一下无任何响应 HOT 1
- token合法性问题 HOT 2
- JWT_SECRET_KEY 生成的问题
- 项目中不存在UsernamePasswordAuthenticationFilter这个过滤器
- 关于配置context-paht为/api的配置 HOT 3
- 对于登录方面有一些疑问 HOT 3
- 你好!提供优化建议!
- jwt是否适合作为后台登录的token
- SpringSecurity介绍.md文件问题
- post调试工具 HOT 1
- 创建数据库表的SQL语句在哪呢?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-security-jwt-guide.