1

我有以下设置

@Service
public class TestDispatcherImpl implements Dispatcher <MobilePushNotification> {

    @Autowired
    private A a;

    @Autowired
    private B b;

    @Autowired
    private C c;


    @PostConstruct
    public void initialize() {} {
     b.someMethod(); //GETTING A NULL POINTER EXCEPTION, 
                     //in fact all the beans are null

    }
}

public interface Dispatcher <T extends Notification> {

}

怎么了 ?

4

2 回答 2

4

尝试删除多余的花括号:

public void initialize() {} {
                         ^^
 b.someMethod(); //GETTING A NULL POINTER EXCEPTION, 
                 //in fact all the beans are null

}

b.someMethod()我怀疑在Spring 连接依赖项之前调用了您调用的初始化程序块。因此bnull这一点上。

于 2014-08-21T11:18:03.943 回答
0

尝试使用上下文处理它:

这个界面使用简单

org.springframework.beans.factory.config.BeanPostProcessor

于 2016-04-11T20:37:22.947 回答