没有合适的资源?快使用搜索试试~ 我知道了~
Spring的注入在Servlet中使用:在Servlet中使用Spring注入的信息,需要WebApplicationContext这个专门为Web准备的应用上下文
资源推荐
资源详情
资源评论
在Servlet使用Spring注入的信息。
在Servlet中使用Spring注入的信息,需要WebApplicationContext这个专门为Web准备的应用上下文。
1.在web.xml中初始化WebApplicationContext
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener><!--高版本servlet,声明监听-->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet><!--低版本servlet,声明自启动的Servlet-->
<servlet-name>springContextLoaderServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
2.Spring配置示例:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
在Servlet中使用Spring注入的信息,需要WebApplicationContext这个专门为Web准备的应用上下文。
1.在web.xml中初始化WebApplicationContext
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener><!--高版本servlet,声明监听-->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet><!--低版本servlet,声明自启动的Servlet-->
<servlet-name>springContextLoaderServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
2.Spring配置示例:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
资源评论
心柠
- 粉丝: 67
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功