版本:spring3.1+hib4.1+struts2.1

学习项目使用此版本运行时,总是会遇到各样的错误,在这里做一下记录。

问题1:log4j相关

spring的web项目,执行时报错:

信息: Deploying web application archive SSH2.war
log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

根据提示查看:

Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration. log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments. Also see FAQ: Why can't log4j find my properties in a J2EE or WAR application?.

检查思路:

1.所需要的jar文件是否存在 
2.log4j.properties有没有放到src目录下 
3.web.xml中是否配置正确

1、检查log4j配置文件本身及路径,在web.xml中检查关于log4j的配置。

项目中指定加载spring的applicationContext.xml文件。

参考:WARN No appenders could be found for logger的解决方法

仔细查看web.xml发现在加载com.opensymphony.xwork2.config.providers.XmlConfigurationProvider这个listener之后才加载org.springframework.web.util.Log4jConfigListener,把log4j的配置放到org.springframework.web.context.ContextLoader之前。

   <!-- 以下3项参数与log4j的配置相关 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value></param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<!-- end --> <!-- 指定以 listener 方式启动spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

  <!--指定spring 配置文件的配置 -->
  <context-param>
    <param-name>contextConfigLocation </param-name>
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
  </context-param>

按此方式添加后,重新部署执行仍报错。

原来使用的是myecplise10.7,后直接导入到2013版本上直接运行出错,未再提示上述错误。

当启动myeclipse中的Tomcat时,首先他会自动查找工程中用到的自身文件夹下的common/lib下的jar文件,如果找到的话,就进行加载,然后才查找conf/下的log4j.properties等相关的配置文件,正是因为这样,才会报告没有初始化的信息。如果在common/lib下没有找到工程中要用到的jar文件,就先配置conf/下的配置文件,然后到工程中自身包含的lib下查找所用到的jar文件,这时就先把log4j的初始化工作作完了,所以这时在启动Tomcat时就不再提示没有初始化的警告信息了。

总结:在配置各种运行环境的时候,不要认为将要用到的jar文件拷贝到所有的相关的lib文件夹下,就会省很多事,想当然地认为用到时会自动调用,但是当相关配置有先后顺序的时候,会带来很多不必要的麻烦以及意想不到的问题。所以要充分地了解jar文件的用途以及他应该在的位置。

问题2:

严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

解决方法:在web.xml中添加applicationContext.xml的调用即可

问题3:Exception sending context initialized event to listener instance

详细报错:

-- :: org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:)
at org.apache.catalina.core.StandardService.start(StandardService.java:)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:)
at org.apache.catalina.startup.Catalina.start(Catalina.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:)
at org.hibernate.cfg.Configuration.add(Configuration.java:)
at org.hibernate.cfg.Configuration.add(Configuration.java:)
at org.hibernate.cfg.Configuration.add(Configuration.java:)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
... more
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:)
... more
-- :: org.apache.catalina.core.StandardContext start
严重: Error listenerStart
-- :: org.apache.catalina.core.StandardContext start
严重: Context [/News] startup failed due to previous errors

查看hib相关的文件,生成实体类映射文件的头文件存在空格,如Topic.hbm.xml中“mapping-3.0.dtd ">”中dtd与“之间有空格,去掉此空格后,再次运行后就不再报此错了。

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">

myecplise ssh项目配置上遇到的问题的更多相关文章

  1. SSH项目配置数据源的方法(jndi)

    1.在tomcat6.0/conf/context.xml加入以下代码 [xhtml] view plain copy     <Resource name="jdbc/oracleD ...

  2. SSH实战 · 唯唯乐购项目(上)

    前台需求分析 一:用户模块 注册 前台JS校验 使用AJAX完成对用户名(邮箱)的异步校验 后台Struts2校验 验证码 发送激活邮件 将用户信息存入到数据库 激活 点击激活邮件中的链接完成激活 根 ...

  3. windows下GitHub的安装、配置以及项目的上传过程详细介绍

    概要 本文主要介绍了在Win10系统中安装Github终端.如何配置安装好的Git终端以及如何利用Git终端将自己的项目上传到远程服务器中 操作必备 win10系统电脑一台.良好的互联网连接.GitH ...

  4. SSH项目搭建(五)——web.xml文件配置

    上一章写到pom.xml有一个报错,说找不到web.xml文件.确实是这样的,因为我们用maven搭建的web层里就是没有这个文件.我们能看到,webapp文件夹里是空的. 没有,就想办法把它弄出来. ...

  5. Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程

    最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...

  6. 剖析项目多个logback配置(上)

    来源:http://www.cnblogs.com/guozp/p/5949744.html 以下两个是我在使用slf4j + logback时候日志提示的问题,问题不大,都是WARN,并不真正影响运 ...

  7. nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  8. 在Eclipse上使用egit插件通过ssh协议方式上传项目代码的具体步骤

    在Eclipse上使用egit插件通过ssh协议方式上传项目代码 前戏: 使用ssh方式可以不通过https协议,避免直接提供账号密码的方式上传项目到git在线服务器,如Bitbucket.GitHu ...

  9. SSH项目与SSM项目的进入首页的方法

    SSH项目中: jsp页面一般都是存放在WEB-INF下面的目录下,这样我们就不能直接访问到这些jsp页面了,保证了页面的安全性. 在struts的管理中,是利用action来实现页面的跳转,进入in ...

随机推荐

  1. mybatis根据数据库表结构自动生成实体类,dao,mapper

    首先, pom需要引入 <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifac ...

  2. Apache Curator is a Java/JVM client library for Apache ZooKeeper

    http://curator.apache.org/index.html Welcome to Apache Curator What is Curator? Curator n ˈkyoor͝ˌāt ...

  3. MySQL高级知识(九)——慢查询日志

    前言:慢查询日志是MySQL提供的一种日志记录,它记录MySQL中响应时间超过阈值的语句,具体指运行时间超过long_query_time值的sql语句,该sql语句会被记录到慢查询日志中.慢查询日志 ...

  4. Scrapy 框架 总结

    总结: 1.中间件:下载中间件(拦截请求和响应) - process_request: - prceess_response: - process_exception: - 请求: - UA伪装: - ...

  5. 如何弄清Linux系统运行何种系统管理程序

    如何弄清Linux系统运行何种系统管理程序 虽然我们经常听到系统管理器System Manager这词,但很少有人深究其确切意义.现在我们将向你展示其区别. 我会尽自己所能来解释清楚一切.我们大多都知 ...

  6. python requests提示警告InsecureRequestWarning

    在Python3中使用以下代码报错: import requests response = requests.get(url='', verify=False) 错误代码如下: InsecureReq ...

  7. display为inline-block的元素有内容和没有内容情况下高度不一致的问题

    这两天发现一个问题,就是display为inline-block的元素有内容和没有内容情况下高度不一致,虽然不会出现元素中没内容的情况,但是我还是决定必须解决这个问题,可能我有一些轻微的强迫症. &l ...

  8. 吴恩达课后作业学习2-week3-tensorflow learning-1-基本概念

    参考:https://blog.csdn.net/u013733326/article/details/79971488 希望大家直接到上面的网址去查看代码,下面是本人的笔记  到目前为止,我们一直在 ...

  9. SWIG 的应用(一)

    用 C/C++ 扩展 Python. - 如果仅使用标准 C 库函数,则可以使用 Python 自带的 ctypes 模块,或者使用 cffi. - 如果要使用自定义 C/C++ 函数,又不怕写 wr ...

  10. 接口测试,获取登录后的cookies

    参见: http://www.cnblogs.com/testwang/p/6023394.html