我搜索了高低,但仍然无法找到这个非常烦人的问题的简单答案,
我遵循了这个伟大的指南:JWT 与多服务应用程序一切都很好,但在指南的最后,建议我们创建一个 config-service(module) ,我已经完成了。
问题是我无法覆盖 JwtConfig 类的默认配置
项目结构如下:
-config-service
| JwtConfig.java
\
| resources
\
| jwtConfig.properties
-other-service (add dependency in the pom file of the config-service)
|
someOtherclass.java (import the JwtConfig class & using @Bean to initialize )
JwtConfig 类:
/*all the imports*/
@PropertySource(value = "classpath:jwtConfig.properties")
public class JwtConfig {
@Value("${security.jwt.uri:/auth/**}")
private String Uri;
@Value("${security.jwt.header:Authorization}")
private String header;
@Value("${security.jwt.prefix:Bearer }")
private String prefix;
@Value("${security.jwt.expiration:#{24*60*60}}")
private int expiration;
@Value("${security.jwt.secret:JwtSecretKey}")
private String secret;
//getters
someOtherclass.java:
/*imports*/
@Configuration
@EnableWebSecurity
public class SecurityCredentialsConfig extends WebSecurityConfigurerAdapter
{
private JwtConfig jwtConfig;
@Autowired
public void setJwtConfig(JwtConfig jwtConfig) {
this.jwtConfig = jwtConfig;
}
@Bean
public JwtConfig jwtConfig() {
return new JwtConfig();
}
/*other code*/
问题是我在 jwtConfig.properties 文件中放入什么参数并不重要,
例如:
security.jwt.uri=test
当其他服务加载它时,它不会出现在 JwtConfig bean 中。
仅加载默认的@Value。
有人可以提供任何建议吗?我该如何修复它?
非常感谢!