6

Actually, I have had this question for a quite long time already, I'm using SpringMVC + Hibernate3 + Spring Security as the framework, tomcat 7 as the container, however after add the filter and interceptor in the web.xml, there are sooooo many debug informations print into the console, no matter how I change the configuration files, those debug informations always staying there, please help.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>iCubeHRS</display-name>

   <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>           
            /WEB-INF/dispatcher-servlet.xml
            /WEB-INF/spring-security.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> 

   <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

log4j

# Root logger option
log4j.rootLogger=WARN, file
log4j.category.org.springframework = OFF

log4j.logger.org.springframework.aop.framework.autoproxy=OFF

log4j.logger.org.apache=OFF,R

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=c\:\\test\\logging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

those bloody debug information in console(there are far more than that I pasted here ):

14:16:21.617 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
14:16:21.618 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
14:16:21.618 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@79d4461c]
14:16:21.619 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
14:16:21.625 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
14:16:21.626 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
14:16:21.626 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@63f9e51e]
14:16:21.627 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0'
14:16:21.627 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'
14:16:21.627 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1'
14:16:21.627 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0'
14:16:21.627 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#1'
14:16:21.628 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0'
14:16:21.628 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'
14:16:21.629 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1'
14:16:21.629 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0'
14:16:21.629 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#1'
14:16:21.629 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
14:16:21.629 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
14:16:21.630 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0'
14:16:21.630 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#1'
14:16:21.631 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
14:16:21.631 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
14:16:21.631 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0'
14:16:21.631 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#1'
14:16:21.632 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0'
14:16:21.632 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0'
14:16:21.632 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0'
14:16:21.633 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0'
14:16:21.633 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0'
14:16:21.633 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0'
14:16:21.635 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
14:16:21.642 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
14:16:21.643 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
14:16:21.643 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@2111dbcb]
14:16:21.644 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.view.InternalResourceViewResolver#0'
14:16:21.645 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.view.InternalResourceViewResolver#0'
14:16:21.648 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
14:16:21.655 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
14:16:21.656 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
14:16:21.656 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@22f73351]
14:16:21.659 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
14:16:21.659 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Published WebApplicationContext of servlet 'dispatcher' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher]
14:16:21.659 [localhost-startStop-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 2535 ms
14:16:21.659 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Servlet 'dispatcher' configured successfully

=====================================update 1 ======================================

updated Log4j files

log4j.rootLogger=WARN,console,R

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.threshold=WARN
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] - %c -%F(%L) -%m%n

log4j.org.springframework.web=WARN

log4j.logger.org.springframework.web.servlet.mvc = OFF

log4j.logger.org.springframework.security=OFF 

org.springframework.security.level=WARN
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Saorikido
  • 2,173
  • 2
  • 26
  • 37
  • 1
    You are aware that your configuration is flawed (you are basically duplicating your beans!). Both the `ContextLoaderListener` and `DispatcherServlet` are loading the **dispatcher-servlet.xml**. Also make sure you don't have a log4j around somewhere else (like for instance inside tomcat) as that will not be able to read your log4j configuration. Also make sure you don't have duplicate configuration (a log4j.xml and a log4j.properties, I sternly suggest using the first option as it is IMHO easier to read). – M. Deinum Nov 15 '13 at 08:19
  • @M.Deinum the reason why I put **dispather-servlet.xml** into the ContextConfiguration scope is that I have to initial all the database connection before **spring-security.xml** was loaded, 'cause I need the **datasource** bean to be injected to spring-security.xml to implement the authentication module, as you mentioned, this will cause'duplicating your beans' issue, but I didn't get any error or exception about this, if it does duplicated, how to avoid it, thank you – Saorikido Nov 15 '13 at 12:54
  • @M.Deinum if I remove **dispatcher-servlet.xml** from ContextConfiguration scope, does it help to avoid duplicating beans issue? – Saorikido Nov 15 '13 at 16:55
  • 1
    Yes. It will not give you errors but it (might and at some point will) lead to strange transaction issues, maybe memory issues etc. So duplication should be avoided. In general your `ContextLoaderListener` should load all generic stuff (datasources, services, repositories etc.) and your `DispatcherServlet` only the web related resources (controllers, view resolvers, views etc.). – M. Deinum Nov 15 '13 at 17:29
  • @M.Deinum thank you so much for pointing out the flawed configuration, now the application starts much more faster than before. but according to your suggestion, I checked all the places and make sure there is only one log4j is set up, but I still can't disable that bloody logs info, please see my updated log4j file. – Saorikido Nov 16 '13 at 03:45
  • 1
    As mentioned, if you don't have log4j in your web application (or somewhere in the path of the app server) the configuration is basically useless. So my guess would be that you have log4j in your application server (and that is loaded before the one in the application). Which means that that one cannot load the resources from inside the web application. – M. Deinum Nov 17 '13 at 12:10
  • @M.Deinum yes, there are other log libs I added long time back, after removed them it works properly, thank you so much. – Saorikido Dec 05 '13 at 09:40

2 Answers2

1

Actually the answer is here https://stackoverflow.com/a/23254829/1000011

Create a logback.xml file in your resources directory containing:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>web - %date [%thread] %-5level %logger{36} - %message%n
            </pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="WARN" />

    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>
Community
  • 1
  • 1
opticyclic
  • 7,412
  • 12
  • 81
  • 155
0

(Question answered in the comments and question edits by the OP. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

To disable the console debug information, you need add the log4j configuration file then modify the log level to above DEBUG, in this case, my log4j doesn't work properly 'Coz I put another log library into the project, as @M.Deinum mentioned, 'make sure you don't have a log4j or other log libs around somewhere else'.

In web.xml is flawed (basically duplicating the beans), because I put dispatcher-servlet.xml into context loader configuration scope, after that the dispatcher servlet loaded it again, sometime we need initial some beans first before some others like datasource bean, in my case, spring security needs a datasource to read the authority before the request goes into dispatcher, so that I have to initial datasource at the first place, also as @M.Deinum mentioned, "In general your ContextLoaderListener should load all generic stuff (datasources, services, repositories etc.) and your DispatcherServlet only the web related resources (controllers, view resolvers, views etc.)." solved this issue.

Community
  • 1
  • 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129