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 人气:1250
分享到:
blog comments powered by Disqus

相关文章

  • Tomcat Web application using web.xml control Xiangjie (1) 2010-07-30

    Transfer from: http://fanqiang.chinaunix.net/app/web/2006-04-29/4122.shtml Tomcat Web application using web.xml control Xiangjie (1) Study: feng_sundy Source: unknown (2006-04-29 13:39:34) A definition of the head and the root element Deployment desc

  • 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: Th

  • 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

  • [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

  • 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 p

  • 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: W

  • java Code Generation 2010-05-01

    1. Generated verification code: using technology jsp, servlet 2. Generated verification code in the servlet: package servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.I

  • ORACLE statements in Java code to perform insert operation error: ORA-00911: invalid character 2010-05-12

    For insert operations sql: INSERT INTO FB10_COLLIGATE_SATAISTIC (colligate_statistic_id, inner_code, report_date) VALUES (COLLIGATE_STATISTIC_ID_SEQ.NEXTVAL, #innerCode#, #reportDate#); Problem description: sql is simple to insert data into a table a

  • Android layout java code to achieve 2010-06-27

    General situations in which the Android layout we often use program XML documentation in preparing, this can increase development efficiency, but given the secure code and the implementation of efficiency, you can perform create Java code, although A

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

processed in 0.558 (s). 13 q(s)