• 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_requestScope


    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
    <%@ page import="org.springframework.web.context.*" %>
    <%@ page import="org.springframework.web.context.support.*" %>
    <%@ page import="org.crazyit.app.service.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Spring Bean的作用域</title>
    </head>
    <body>
    <%
    // 获取Web应用初始化的Spring容器
    WebApplicationContext ctx = 
        WebApplicationContextUtils.getWebApplicationContext(application);
    // 两次获取容器中id为p的Bean
    Person p1 = (Person)ctx.getBean("p");
    Person p2 = (Person)ctx.getBean("p");
    out.println((p1 == p2) + "<br/>");
    out.println(p1);
    %>
    </body>
    </html>
    <?xml version="1.0" encoding="GBK"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
        <!-- 指定使用request作用域 -->
        <bean id="p" class="org.crazyit.app.service.Person"
            scope="request"/>
    </beans>
    <?xml version="1.0" encoding="GBK"?>
    <project name="spring" basedir="." default="">
        <property name="src" value="src"/>
        <property name="dest" value="classes"/>
    
        <path id="classpath">
            <fileset dir="lib">
                <include name="**/*.jar"/>
            </fileset>
            <pathelement path="${dest}"/>
        </path>
    
        <target name="compile" description="Compile all source code">
            <delete dir="${dest}"/>
            <mkdir dir="${dest}"/>
            <copy todir="${dest}">
                <fileset dir="${src}">
                    <exclude name="**/*.java"/>
                </fileset>        
            </copy>
            <javac destdir="${dest}" debug="true" includeantruntime="yes"
                deprecation="false" optimize="false" failonerror="true">
                <src path="${src}"/>
                <classpath refid="classpath"/>
                <compilerarg value="-Xlint:deprecation"/>
            </javac>
        </target>
    
    </project>
    <?xml version="1.0" encoding="GBK"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <listener>
            <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>
    
    </web-app>
    package org.crazyit.app.service;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public class Person
    {
        private int age;
    }
  • 相关阅读:
    poj2002 poj3432 正方形个数 (hash,二分)
    置换群
    poj1995快速幂取余
    poj3983 (24点)
    判断二叉树是否是完全二叉树
    判断两个二叉树是否同构(相似)
    poj2187 最远点对问题
    poj2079 求最大的三角形面积
    poj3714 最近点对
    Linq学习笔记延迟操作符(分区操作符)
  • 原文地址:https://www.cnblogs.com/tszr/p/12370301.html
Copyright © 2020-2023  润新知