springMVC注解掃面順序問題

3277 ワード

サーバー起動時のロードプロファイルの順序はweb.xml-root-context.xml(Springのプロファイル)-servlet-context.xml(Spring MVCのプロファイル)ですので、root-context.xmlプロファイルではControllerが先にスキャン組み立てられますが、このときserviceはまだ事務強化処理が行われていません.Seviceはそのままです.(事務処理を強化していないので、事務処理能力がない)
だからappication Contect.xmlで必ず先にserviceをスキャンします.

    <context:component-scan base-package="com">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    context:component-scan>```
その後context-servlet.xmlでスキャンcontroler:

    <context:component-scan base-package="com">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    context:component-scan>
このスキャン順序に従わないと、トランザクションが失効したり、spring securityの時にFilter InvocationSecurity Metadata Sourceのクラスを実現することができます.
@Autowired
public IAuthoritiesService authoritiesService;
......
private void loadResourceDefine() {
/*       DAO  ,   DB  。 
        resourceMap = new HashMap>();
        Collection atts = new ArrayList();
        ConfigAttribute adminCA = new SecurityConfig("ROLE_ADMIN");
        atts.add(adminCA);
        ConfigAttribute userCA =  new SecurityConfig("ROLE_USER");
        atts.add(userCA);
        resourceMap.put("/index.jsp", atts);*/
        //resourceMap = authoritiesService.getResourceMap();    ,   。
        authoritiesService = (IAuthoritiesService)WebApplicationUtils.getApplicationContext().getBean("authoritiesService");
        resourceMap = authoritiesService.getResourceMap();
        System.out.println("---------------------->     :loadResourceDefine()");
    }
service(Null Point Exception)を呼び出してデータベースからリソース認証などを取得できませんでした.