zoukankan      html  css  js  c++  java
  • web.xml包含struts2整合spring3以及配置log4j和数据连接池

    web.xml
     1 <?xml version="1.0" encoding="UTF-8"?>
    2 <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
    3 <display-name>jfzdataexchangetowap</display-name>
    4 <context-param>
    5 <param-name>contextConfigLocation</param-name>
    6 <param-value>/WEB-INF/applicationContext.xml</param-value>
    7 </context-param>
    8 <context-param>
    9 <param-name>xmlFile</param-name>
    10 <param-value>WEB-INF/proxool.xml</param-value>
    11 </context-param>
    12
    13 <context-param>
    14 <param-name>log4jConfigLocation</param-name>
    15 <param-value>/WEB-INF/classes/log4j.properties</param-value>
    16 </context-param>
    17
    18 <filter>
    19 <filter-name>struts2</filter-name>
    20 <filter-class>
    21 org.apache.struts2.dispatcher.FilterDispatcher
    22 </filter-class>
    23 </filter>
    24 <filter>
    25 <filter-name>struts-cleanup</filter-name>
    26 <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    27 </filter>
    28 <filter>
    29 <filter-name>openSessionInView</filter-name>
    30 <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    31 </filter>
    32
    33 <filter-mapping>
    34 <filter-name>struts2</filter-name>
    35 <url-pattern>*.action</url-pattern>
    36 </filter-mapping>
    37
    38
    39 <listener>
    40 <listener-class>com.xgr.util.ProxoolInitListener</listener-class>
    41 </listener>
    42 <!-- 启动spring -->
    43 <listener>
    44 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    45 </listener>
    46 <!-- 启动log4j -->
    47 <listener>
    48 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    49 </listener>
    50
    51 <servlet>
    52 <servlet-name>ProxoolAdmin</servlet-name>
    53 <servlet-class>
    54 org.logicalcobwebs.proxool.admin.servlet.AdminServlet
    55 </servlet-class>
    56 <init-param>
    57 <param-name>output</param-name>
    58 <param-value>full</param-value>
    59 </init-param>
    60 </servlet>
    61 <servlet-mapping>
    62 <servlet-name>ProxoolAdmin</servlet-name>
    63 <url-pattern>/ProxoolAdmin</url-pattern>
    64 </servlet-mapping>
    65
    66
    67 <welcome-file-list>
    68 <welcome-file>index.jsp</welcome-file>
    69 </welcome-file-list>
    70
    71 </web-app>

    解决了proxool连接池在使用过程中报错的问题,一般都是报访问一个未注册的数据源名称的问题,或者说是spring的启动在连接池启动之前的问题,解决方案是使用一个过滤器

    View Code
    1     <listener>
    2 <listener-class>com.xgr.util.ProxoolInitListener</listener-class>
    3 </listener>
    ProxoolInitListener
     1 public class ProxoolInitListener implements ServletContextListener {
    2 private static final Log LOG = LogFactory.getLog(ProxoolInitListener.class);
    3
    4 private static final String XML_FILE_PROPERTY = "xmlFile";
    5
    6 private static final String PROPERTY_FILE_PROPERTY = "propertyFile";
    7
    8 private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown";
    9
    10 private boolean autoShutdown = true;
    11
    12 public void contextInitialized(ServletContextEvent contextEvent) {
    13 ServletContext context = contextEvent.getServletContext();
    14
    15 String appDir = contextEvent.getServletContext().getRealPath("/");
    16
    17 Properties properties = new Properties();
    18
    19 Enumeration names = context.getInitParameterNames();
    20 while (names.hasMoreElements()) {
    21 String name = (String) names.nextElement();
    22 String value = context.getInitParameter(name);
    23
    24 if (name.equals(XML_FILE_PROPERTY)) {
    25 try {
    26 File file = new File(value);
    27 if (file.isAbsolute()) {
    28 JAXPConfigurator.configure(value, false);
    29 } else {
    30 JAXPConfigurator.configure(appDir + File.separator
    31 + value, false);
    32 }
    33 } catch (ProxoolException e) {
    34 LOG.error("Problem configuring " + value, e);
    35 }
    36 } else if (name.equals(PROPERTY_FILE_PROPERTY)) {
    37 try {
    38 File file = new File(value);
    39 if (file.isAbsolute()) {
    40 PropertyConfigurator.configure(value);
    41 } else {
    42 PropertyConfigurator.configure(appDir + File.separator
    43 + value);
    44 }
    45 } catch (ProxoolException e) {
    46 LOG.error("Problem configuring " + value, e);
    47 }
    48 } else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) {
    49 autoShutdown = Boolean.valueOf(value).booleanValue();
    50 } else if (name.startsWith("jdbc")) {// 这里原来不是jdbc,用原来的报错,这里是说在找properties文件时,找以jdbc开头的,这里用的xml文件,所以这里无所谓
    51 properties.setProperty(name, value);
    52 }
    53 }
    54
    55 if (properties.size() > 0) {
    56 try {
    57 PropertyConfigurator.configure(properties);
    58 } catch (ProxoolException e) {
    59 LOG.error("Problem configuring using init properties", e);
    60 }
    61 }
    62 }
    63
    64 public void contextDestroyed(ServletContextEvent contextEvent) {
    65 if (autoShutdown) {
    66 ProxoolFacade.shutdown(0);
    67 }
    68
    69 }
    70
    71 }



     

  • 相关阅读:
    PHP文件系统处理(二)
    PHP中的文件系统处理(一)
    PHP中常用正则表达式大全
    PHP中的正则表达式的使用
    SLF4J日志框架
    内部类
    计算机存储单位
    Maven 要点
    Maven 父类工程创建及引用
    Eclipse Maven Web项目创建
  • 原文地址:https://www.cnblogs.com/fangj/p/2232760.html
Copyright © 2011-2022 走看看