Spring在javaweb工程中的简单配置与应用
来源:互联网 发布:水刀编程软件 编辑:程序博客网 时间:2024/04/30 22:02
一、导入spring与web相关的jar包。这里注意由于我之前起的web项目,然后是通过java的application做的哦实验,因此所有的jar包都是导入在了src的library中。在运行web的时候会出现各种class找不到,因此还需要将jar包导入到/WebContent/WEB-INF/lib中。
二、在web.xml中添加如下关于spring的代码:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>这里classpath:applicationContext-*.xml表示spring的配置文件从src文件下搜索以applicationContext-*开头的文件。
三、servlet中如果需要spring提供的bean的话,如下使用:
ServletContext servletContext = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); UserDao userDao = (UserDao)ctx.getBean("mysqlDaoImpl");
0 0
- Spring在javaweb工程中的简单配置与应用
- redis 在spring boot工程中的应用(四) 图片的读取与缓存 byte string
- UEditor在JavaWeb中的应用
- UEditor在JavaWeb中的应用
- UEditor在JavaWeb中的应用
- spring在web应用中的配置
- Spring在Web应用中的配置
- log4j在spring应用中的配置
- Quartz在Spring中的简单配置
- velocity模板在spring中的简单配置
- velocity模板在spring中的简单配置
- redis 在spring boot工程中的应用(一)
- redis 在spring boot工程中的应用(二)
- 在Idea下配置JavaWeb工程
- redis 在spring boot工程中的应用(三) 问题发现与解决 :反序列化 报错
- 【Spring】Spring在JavaWeb工程中整合log4j
- iOS_11_XMPP在工程中的应用
- java3D技术在JavaWeb中的应用
- 【奇思妙想】月球上也能有WiFi?
- 快速排序
- 编程新手表示很想知道JAVA中Bean是什么?
- myeclipse8.5优化
- 将逻辑卷降为物理分区
- Spring在javaweb工程中的简单配置与应用
- CSS3实现三角框
- c++输入输出格式 %i
- Elasticsearch——Templates 模板
- 你好啊
- C++构造函数、拷贝构造函数、赋值运算符漫谈(一)——函数参数传递
- 把Gps坐标转成百度坐标的java方法
- 程序员可以在周末做的8件事
- Hbase在数据统计中的应用心得