我有一个属性的类配置属性为空春季启动
@ConfigurationProperties(prefix = ShiroProperties.SHIRO_PREFIX)
public class ShiroProperties {
public static final String SHIRO_PREFIX = "shiro";
private String urlLogin;
private String urlSuccessed;
和配置类
@Configuration
@EnableConfigurationProperties({ ShiroProperties.class })
public class ShiroConfig implements ApplicationContextAware {
ApplicationContext applicationContext;
@Autowired
private ShiroProperties shiroProperties ;
shiroProperties是空的,但我可以找到它在ShiroConfig值使用
applicationContext.getBean(ShiroProperties.class)
我的应用等级:
@SpringBootApplication
public class Bootstrap {
public static void main(String[] args) {
SpringApplication.run(Bootstrap.class, args);
}
}
奇怪的是,我可以在其他项目中使用类似的代码运行成功,但是这个。
我不知道,但我觉得你应该加上'@ Component'为'ShiroProperties'(按[春季启动外部配置文件](HTTPS ://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html)) –
我看到之前,我试过了,但它没有工作。无论如何,谢谢 – Dean
我发现这个奇怪问题的原因,如果添加由'@ Bean'注释的'LifecycleBeanPostProcessor',那么'@ Autowired'不起作用。 'LifecycleBeanPostProcessor'类来自shiro。 – Dean