在jwt中@Value失效,发现是@Value的加载顺序问题,于是产生以下解决方案:
1.创建一个类,并加入spring的组件,在这个组件中用@value获取配置信息
@Component
public class JwtProperty {
@Value("${SSOSwitch}")
private String ssoSwitch;
public String getSsoSwitch() {
return ssoSwitch;
}
public void setSsoSwitch(String ssoSwitch) {
this.ssoSwitch = ssoSwitch;
}
public JwtProperty() {
this.setSsoSwitch(ssoSwitch);
}
}
2.在jwt中用这种形式获取到JwtProperty的实例
@Resource
private JwtProperty jwtProperty = (JwtProperty) SpringContextUtils.getBean(JwtProperty.class);
附:SpringContextUtils代码
@Component
public class SpringContextUtils implements ApplicationContextAware {
/** * 上下文对象实例 */
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/** * 获