1
런타임 중에 bean 속성 값을 변경하려고합니다.런타임 중에 스프링 콩을 다시로드하십시오.
WebConfig
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Autowired
private SecurityService service;
@Bean
public SecurityPolicy securityPolicy() {
SecurityPolicy policy = new SecurityPolicy();
//takes data from db, it works fine
policy.setMaxAttempt = service.getMaxAttempts();
return policy;
}
}
컨트롤러
@Controller
public class SecurityPolicyController {
@Autowired
private SecurityPolicy policy;
@Autowired
private ApplicationContext context;
@Autowired
private SecurityService service;
@RequestMapping(value = "/security")
public ModelAndView update() {
ModelAndView model = new ModelAndView();
//set data to db, it works fine aswell
service.setMaxAttempts(7);
//now i am trying to reload my beans
((ConfigurableApplicationContext)context).refresh();
//something reloading but i still get the same value
System.out.println(policy.getMaxLoginAttempts());
model.setViewName("security");
return model;
}
}
값 변경은 서버가 재부팅 될 때만 발생한다. 런타임 중에 빈 재로드를 수행하는 방법을 제안하거나 내가 뭘 잘못하고 있는지 말할 수 있습니까? 모든 도움을 주셨습니다
SecurityPolicy와 콩이 다른 서비스에 주입,이 서비스에이 방법 난 아직 – Coder
곳을 이전 값이 서비스는 그 가치를 얻습니까? 정적 소스? – Lino
SecurityPolicy bean – Coder