Pring Beanfactory at the jsp, servlet, web.xml and other configuration

Keywords: spring beanfactory
Spring in the web application called the Beanfactory

1) Configure web.xml
Java code
<? xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE web-app
PUBLIC "- / / Sun Microsystems, Inc. / / DTD Web Application 2.3 / / EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name> contextConfigLocation </ param-name>
<! - Configuration loaded bean factory xml ->
<param-value>
WEB-INF/applicationContext *. xml
classpath: applicationContext-datasource.xml
classpath: applicationContext-hibernate.xml
classpath: applicationContext-dao.xml
classpath: applicationContext-service.xml
</ param-value>
</ context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</ listener-class>
</ listener>
</ web-app>

<? xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE web-app
PUBLIC "- / / Sun Microsystems, Inc. / / DTD Web Application 2.3 / / EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name> contextConfigLocation </ param-name>
<! - Configuration loaded bean factory xml ->
<param-value>
WEB-INF/applicationContext *. xml
classpath: applicationContext-datasource.xml
classpath: applicationContext-hibernate.xml
classpath: applicationContext-dao.xml
classpath: applicationContext-service.xml
</ param-value>
</ context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</ listener-class>
</ listener>
</ web-app>
2) Jsp page called spring
Java code
org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
pageContext.getServletContext (). getAttribute (org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
pageContext.getServletContext (). getAttribute (org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
3) Servlet call spring
Java code
ServletContext context = this.getServletContext ();
org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
context.getAttribute (org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

ServletContext context = this.getServletContext ();
org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
context.getAttribute (org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
4) ClassPath load
Java code
ApplicationContext beanFactory = new ClassPathXmlApplicationContext (
new String [] ( "applicationContext-datasource.xml",
"applicationContext-hibernate.xml",
"applicationContext-service-freemarker.xml",
"applicationContext-service.xml"
));

分类:Java 时间:2009-03-03 人气:1229
分享到:
blog comments powered by Disqus

相关文章

  • servlet in the web.xml configuration file parameters in context-param and the init-param District 2010-06-17

    web.xml which can be defined two parameters: (1) application within the parameters stored in servletcontext, in web.xml, configured as follows: <context-param> <param-name> context / param </ param-name> <param-value> avalible

  • 解析web.xml中在Servlet中获取context-param和init-param内的参数 2013-11-20

    本篇文章是对web.xml中在Servlet中获取context-param和init-param内的参数进行了详细的分析介绍,需要的朋友参考下 web.xml里面可以定义两种参数:1.application范围内的参数,存放在servletcontext中,在web.xml中配置如下: <context-param> <param-name>context/param</param-name> <param-value>avalible duri

  • java code for the return JSON or XML data (extJs) 2010-06-10

    package com.hrm.util; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONObject; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; /** * Title: Ext JS Auxiliary classes * Description: This cl

  • Response implementation of the java code files to download 2010-08-27

    // This is to achieve download class (servlet), Specific ideas the code below : // Can also connect to the database package com.message; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class FileDownServle

  • How to use the js code or Java code jsp tag 2011-05-05

    JSP tag is still very convenient, such as Struts, Spring and other JSP tags provided to us, you can use them to get some variable or calculation. For example struts2 of <s:url value="/admin/unmi.action"/> automatically for us in front of t

  • Agile Development of Java code to write high-quality 2009-12-24

    Agile development concept has been popular for a very long time, the development of agile development iteration stage, we can through the five steps to effectively improve the quality of the entire project code. Java project development process, due to th

  • [Change] agile development of high-quality Java code to write 2009-09-29

    Agile development concept has been popular for a very long time, the development of agile development iteration stage, we can through the five steps to effectively improve the quality of the entire project code. Java project development process, due to th

  • WebService development example (java code) 2010-03-19

    WebService is an advanced application, with the previous learning Struts, Spring, Hibernate and other frameworks different. WebService is a service-oriented architecture (SOA), looks like a larger framework than SSH. In the end it is what for? What i ...

  • Agile Java code to write high-quality 2010-03-10

    Source: IBM dW / Wang Yongkui | De idea of agile development has been popular for a long time in Agile Development Kaifa iteration stage, we can through the five steps to effectively improve the entire project code quality. Java project development proces

  • Java code using JDEE as a reader 2010-04-06

    Emacs is absolutely great software, some shameless villain than the secular far to great, but some of its design to the letter and still affect a lot of development tools. JDEE is a great software, I JDEE mailing list, get feedback very very happy: Welcom

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.337 (s). 12 q(s)