【发布时间】:2019-03-11 09:50:09
【问题描述】:
我已经搜索了高低,但我仍然无法找到这个非常烦人的问题的简单答案,
我遵循了这个很棒的指南: JWT with multi service app 一切都很好,但在指南的最后,我们建议创建一个 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。
有人可以给点建议吗?我该如何解决? 非常感谢!
【问题讨论】:
-
@Mikhail,对不起,我有点困惑,我应该在哪里使用 PropertySources 注释?你能提供一个小例子吗,我没能从你的回答中理解它
标签: maven spring-boot multi-module application.properties java-11