user874722
user874722

Reputation: 149

Spring MVC WebApp Issue

We are using Spring MVC 3 for our WebApplication. I see a strange behavior from the application. When a user perform a action (ex: button click) , i see the controllers logs are logged twice and so are the subsequent calls in the controller .Controllers we used are default,singleton. So,

  1. I would like to print the thread information in the controller(like threadName. tried Thread.getName()..was Unique).. any help?

  2. How do i make sure that there is only one Spring container loaded? -- any Suggestions?

log4j Prop:

    `log4j.appender.ROLL_FILE=org.apache.log4j.RollingFileAppender 
     log4j.appender.ROLL_FILE.File=/ws/was/dept/logs/${module.jvm.instance}_module.log
     log4j.appender.ROLLING_FILE.Append=true 
     log4j.additivity.ROLLING_FILE.Append=false 
     log4j.appender.ROLLING_FILE.MaxFileSize=10MB 
     log4j.appender.ROLLING_FILE.MaxBackupIndex=20 
     log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout 
     log4j.appender.ROLLING_FILE.layout.ConversionPattern=[module] %d - %c -%-4r [%t] %-5p %c %x - %m

Web.xml :

<display-name>module</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/int/root-int-context.xml,/WEB-INF/spring/root-  context.xml</param-value>
   </context-param>
<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
      <servlet>
    <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet.xml</param-value>
      </init-param>          
     <load-on-startup>1</load-on-startup>
  </servlet>`
   <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
 ..........
 .........
 .........

Thanks

Upvotes: 0

Views: 492

Answers (2)

RonK
RonK

Reputation: 9652

  1. Use Thread.getId() to get the unique thread ID.
  2. Check your logger configuration - I'm guessing you are using log4j or slfj - you might have more than one logger that intercepts the message adds appenders on-top of the appenders defined in the parent logger this might cause two messages to be printed - so check if you have that and define additivity to be false.

Upvotes: 1

Anshu
Anshu

Reputation: 7853

I would like to print the thread information in the controller(like threadName. tried Thread.getName()..was Unique)

  • Use a logging framework. You can find several examples. Check here for configuring logback

How do i make sure that there is only one Spring container loaded?

  • I really don't understand what you mean here, but if have defined contextConfigLocation appropriately in your web.xml, the Spring container would be loaded correctly

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:/META-INF/spring/*.xml 
    </param-value>
    

Upvotes: 0

Related Questions