logging - Why Spring interceptor called twice? -
why spring interceptor called twice in situation?
controller
public class usercontroller { @resource(name="userdao") private userdao userdao; @requestmapping("/user/registuser") public string registuser(httpservletrequest request, model model) { string message = "regist user page!"; model.addattribute("message", message); return "/user/registuser"; } }
interceptor
public class loggerinterceptor extends handlerinterceptoradapter { final protected logger logger = logmanager.getlogger(loggerinterceptor.class); @override public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler) throws exception { logger.debug("===============================================start================================================"); logger.debug("request uri : " + request.getrequesturi()); return super.prehandle(request, response, handler); } @override public void posthandle(httpservletrequest request, httpservletresponse response, object handler, modelandview modelandview) throws exception { logger.debug("================================================end================================================="); super.posthandle(request, response, handler, modelandview); } }
context-servlet.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="com.mamoru.firstweb.*"/> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/user/**"/> <bean id="loggerinterceptor" class="com.mamoru.firstweb.common.logger.loggerinterceptor"/> </mvc:interceptor> </mvc:interceptors> <bean id="viewresolvertiles" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.tiles3.tilesview"/> <property name="contenttype" value="text/html; charset=utf-8"/> <property name="order" value="1"/> </bean> <bean id="viewresolverjstl" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.jstlview"/> <property name="contenttype" value="text/html; charset=utf-8"/> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> <property name="order" value="2"/> </bean> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles3.tilesconfigurer"> <property name="definitions"> <list> <value>/config/tiles/tiles-*.xml</value> </list> </property> </bean> <mvc:resources mapping="/res/**" location="/resources/" /> <mvc:annotation-driven /> </beans>
i use log4j2 project. log under text. think, maybe interceptor called twice.
log
[debug] 13:43:17.693 [http-apr-8080-exec-9] - ===============================================start================================================ [debug] 13:43:17.693 [http-apr-8080-exec-9] - ===============================================start================================================ [debug] 13:43:17.695 [http-apr-8080-exec-9] - request uri : /user/registuser.do [debug] 13:43:17.695 [http-apr-8080-exec-9] - request uri : /user/registuser.do [debug] 13:43:17.709 [http-apr-8080-exec-9] - ================================================end================================================= [debug] 13:43:17.709 [http-apr-8080-exec-9] - ================================================end=================================================
why interceptor called twice? want call inteceptor 1 time.
i added log4j2.xml.
<?xml version="1.0" encoding="utf-8"?> <configuration> <appenders> <file name="filelog" filename="/logs/firstweb.log"> <patternlayout pattern="[%-5level] %d{hh:mm:ss.sss} [%t] - %msg%n"/> </file> <console name="consolelog" target="system_out"> <!--<patternlayout pattern="%d{hh:mm:ss.sss} [%t] %-5level %logger{36} - %msg%n"/>--> <patternlayout pattern="[%-5level] %d{hh:mm:ss.sss} [%t] - %msg%n"/> </console> </appenders> <loggers> <logger name="com.mamoru.firstweb.common.logger.loggerinterceptor" level="trace"> <appenderref ref="filelog"/> <appenderref ref="consolelog"/> </logger> <root level="all"> <appenderref ref="filelog"/> <appenderref ref="consolelog"/> </root> </loggers> </configuration>
Comments
Post a Comment