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

sponsored links
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"
));
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

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

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries