Spring3.2をApacheTilesで使用しています。Rooを使用して多くのサービスクラスを生成しました。jspテンプレートに変数を挿入する簡単な手順を試しています。その部分は正常に機能しますが、サービスBeanを参照する必要がある時点で立ち往生しています。
@Component
public class CustomViewPreparer implements ViewPreparer {
@Autowired
UserProfileService ups;
@Override
public void execute(TilesRequestContext tilesContext,
AttributeContext attributeContext) {
Authentication a = SecurityContextHolder.getContext().getAuthentication();
String name = a.getName(); //get logged in username
UserProfile up = ups.findByUsername(name);
//request.setAttribute("isLoggedIn", up!=null);
}
}
UserProfileServiceの「ups」は常にnullです。私はこれを見つけました: http: //forum.springsource.org/showthread.php ?48950-ViewPreparer-is-triggered-before-Session-starts
しかし、私はその反応を理解していません。ビューを返すたびに変数を挿入することでこれを回避できますが、他の人がこの問題をどのように解決したのか興味があります。