使用spring的自身的listener进行web的配置
web.xml配置如下
<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"><context-param><!--配置spring的配置文件的名称和路径--><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!--启动spring自带的IOC容器的servletContextListener--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener></web-app>
同样配置好bean与上个模拟的实现相同
这次不再servlet中做测试,直接在.jsp中嵌入代码
<%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head><title>$Title$</title></head><body><%//从application域对象中获取IOC容器ApplicationContextctx=WebApplicationContextUtils.getWebApplicationContext(application);//从IOC容器中获取Bean对象Personperson=ctx.getBean(Person.class);//使用bean对象person.hello();%>
这里边的直接写application没看懂。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。