0
私のsrcコードは以下のようになりましたが、これをどのように修正できますか?@Beanの外で帰りましたnullpointerexceptionがありました
@Component("shiroSecurityConfig")
public class ShiroSecurityConfig {
@Autowired (required = true)
private TestService testService;
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilter() {
testService.getrecords(); //this line got null pointer exception.
}
}
コンフィギュレーションコンテキストXMLファイルを共有してください。そうでない場合、コンフィギュレーションcontext.xmlファイルでコンポーネントスキャナを使用してパッケージをスキャンすると、すべてのクラスでオートワイヤリングを実行できます。 –
質問はなぜこの方法で使用していますか? TestServiceがあり、ShiroFilterFactoryBeanが必要なときにいつでもBeanに注入し、getrecords()メソッドを呼び出すことができます。あるいは、TestService#getrecords()に@Beanを追加することもできます。私はそれが良いと思う –