2013年12月10日星期二

springMVC integrate hibernate configuration error

web.xml:

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  
   <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param><!-- 设置配置文件的路径和名字,默认在WEB-INFO下的(servlet-name)spring-servlet.xml -->
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/springMVC.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
<!-- url配置为/,不带文件后缀,会造成其它静态文件(js,css等)不能访问。如配为*.do,则不影响静态文件的访问 -->
</servlet-mapping>


<!-- 配置过滤器,同时把所有的请求都转为utf-8编码 -->  
    <filter>  
        <filter-name>Spring character encoding filter</filter-name>  
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
        <init-param>  
            <param-name>encoding</param-name>  
            <param-value>utf-8</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>Spring character encoding filter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  


then springMVC.xml file content :

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<!-- 自动扫描bean,把作了注解的类转换为bean -->
<context:component-scan base-package="com.jd.oa" />

<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/" p:suffix=".jsp" />

<!-- 上传文件时需要用到的分解器,默认将编码转为utf-8 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="utf-8" />

<!-- 拦截器 
<mvc:interceptors>
<bean class="com.mvc.inteceptor.MyInteceptor" />
</mvc:interceptors>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<bean class="com.mvc.inteceptor.MyInteceptor"></bean>
</list>
</property>
</bean>
-->

<context:property-placeholder location="classpath:dbcp.properties" />
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource" scope="singleton">
<property name="url" value="${url}"></property>
<property name="driverClassName" value="${driverClassName}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
<property name="initialSize" value="${initialSize}"></property>
<property name="maxActive" value="${maxActive}"></property>
<property name="maxWait" value="${maxWait}"></property>
<property name="minIdle" value="${minIdle}"></property>
<property name="maxIdle" value="${maxIdle}"></property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>


<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
</beans>



error message :
java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1526)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter (ApplicationFilterConfig.java: 269)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef (ApplicationFilterConfig.java: 422)
at org.apache.catalina.core.ApplicationFilterConfig . (ApplicationFilterConfig.java: 115)
at org.apache.catalina.core.StandardContext.filterStart (StandardContext.java: 4072)
at org.apache.catalina.core.StandardContext.start (StandardContext.java: 4726)
at org.apache.catalina.startup.HostConfig.checkResources (HostConfig.java: 1284)
at org.apache.catalina.startup.HostConfig.check (HostConfig.java: 1382)
at org.apache.catalina.startup.HostConfig.lifecycleEvent (HostConfig.java: 306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent (LifecycleSupport.java: 142)
at org.apache.catalina.core.ContainerBase.backgroundProcess (ContainerBase.java: 1389)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren (ContainerBase.java: 1653)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren (ContainerBase.java: 1662)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.run (ContainerBase.java: 1642)
at java.lang.Thread.run (Thread.java: 619)
2013-12-10 9:02:32 org.apache.catalina.core.StandardContext start
serious : Error filterStart
2013-12-10 9:02:32 org.apache.catalina.core.StandardContext start
serious : Context [/ oa201312] startup failed due to previous errors
2013-12-10 9:02:42 org.apache.catalina.startup.HostConfig checkResources
Information : Reloading context [/ oa201312]
2013-12-10 9:02:42 org.apache.catalina.core.StandardContext stop
information :... Container org.apache.catalina.core.ContainerBase [Catalina] [localhost] [/ oa201312] has not been started
2013-12-10 9:02:43 org.apache.catalina.core.StandardContext filterStart
Serious : Exception starting filter Spring character encoding filter
java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1526)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter (ApplicationFilterConfig.java: 269)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef (ApplicationFilterConfig.java: 422)
at org.apache.catalina.core.ApplicationFilterConfig . (ApplicationFilterConfig.java: 115)
at org.apache.catalina.core.StandardContext.filterStart (StandardContext.java: 4072)
at org.apache.catalina.core.StandardContext.start (StandardContext.java: 4726)
at org.apache.catalina.startup.HostConfig.checkResources (HostConfig.java: 1284)
at org.apache.catalina.startup.HostConfig.check (HostConfig.java: 1382)
at org.apache.catalina.startup.HostConfig.lifecycleEvent (HostConfig.java: 306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent (LifecycleSupport.java: 142)
at org.apache.catalina.core.ContainerBase.backgroundProcess (ContainerBase.java: 1389)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren (ContainerBase.java: 1653)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren (ContainerBase.java: 1662)
at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.run (ContainerBase.java: 1642)
at java.lang.Thread.run (Thread.java: 619)


web package I imported , why still wrong ! ! !
------ Solution ---------------------------------------- ----
If you springMVC and its configuration are not familiar , I suggest you first look for a project can successfully run the configuration file for each part is what to do with , all by heart , build your future projects and configuration troubleshooting helpful .
------ Solution ---------------------------------------- ----
not load , it shows not found locally , that is not imported this jar, the general schema files are in this jar , the jar view the version and whether the match. Under the project the first clean look .
------ Solution ---------------------------------------- ----

combined with my current project, we have the log levels .
1) Catalina.log
This is the Server level , because we are using Tomcat, different Web Server / Web Container will have its own name.
2) The other is the application level .
here can be divided into several level. More common is the Debug and Info level .
------ For reference only -------------------------------------- -
new error : org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http:/ / www.springframework.org / schema / tx]

This should be a file header errors , but do not check out went wrong :

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
            


------ For reference only ----------------------------------- ----
now springMVC hibernate configuration fast and good, but how to deal with this log ah. Now I do not have the configuration of the contents of the log . Framework should have its own log it. Now I want to add a log to login time for all users of this project , ip, and subsequent operation of fill into their logs and preserved, ( each year produce a log ) , this custom log how to configure and use . Can you give me recommend a few good learning blog ! ! !

没有评论:

发表评论