学習の春のIoCコンテナの展開

コンテナIOC Springフレームワークを使用する場合は、常に最近のプロジェクトにおけるWebプロジェクトで正しいオブジェクトを取得していない
ヌルされ
springiocウェブサーブレットコンテナとコンテナの主な理由は同じではありません
良いIoCコンテナの設立にBeanがサーブレットコンテナにオブジェクトできません後
、両方の空の取得における結果
は以下の通りである処理コードを

web.xmlの

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-config.xml</param-value>
    </context-param>

ログインサーブレット


        HttpServletRequest httpRequest = (HttpServletRequest)request;
        HttpSession session = httpRequest.getSession();
        ApplicationContext applicationContext =
                WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());

        if(session.getAttribute("application")==null){
            session.setAttribute("application",applicationContext);
        }

 user = (user)applicationContext.getBean("usermodel");

セッションここでコンテナは、オブジェクトgetbeanによって取得することができ、右に加え、続いIOCドメインセッションを、持っているかどうかを判断するための

公開された68元の記事 ウォンの賞賛3 ビュー5214

おすすめ

転載: blog.csdn.net/Hqxcsdn/article/details/88911790