我已经阅读了@PostConstruct和init-method,但他们不允许从bean传递args。
this question行的某些内容。但是要传递的args来自实例化bean的类。
简化: Invoker 是实例化 Invoked 类并调用 Invoked.Method(args)的类,其中args来自 Invoker.Args 即可。
问题是我可以在豆中做到这一切吗?谢谢你的帮助。
答案 0 :(得分:2)
IMO类似下面的代码应该可以工作,假设args是作为Invoker类的一部分创建的或者自动装入它:
@Component
class Invoker {
private String[] args = new String[]("1","2","3")
@Autowired
private Invoked invoked;
@PostConstruct
private void init() {
invoked.method(args);
}
}