@Maurizio sorry in the sample app I do not using Spring. I am using Spring
in my projects, sorry for the confusion

And sorry this behavior started on 2.3.7 and 2.3.4.1 does not have this
behavior


On Thu, Apr 25, 2013 at 9:13 AM, Steven Yang <kenshin...@gmail.com> wrote:

> @Maurizio I am indeed using Spring, I will try without Spring.
> @Dave what i mean by "include" is that I use the <include file=""/> tag
>
> I do understand that Interceptor is singleton-ish. And I do understand if
> I defined the same interceptor in two different stacks there should be two
> different instances.
> However the case is that I only have one interceptor stack and two
> packages that shares the same stack but the init() is still being called
> twice. Also I have not declared any other "default" package anywhere in any
> xml, you are seeing all the packages that I have declared which are
> "default" and "example" and yet struts complains that I have declared
> "default" twice.
> If I have two different packages the interceptor should be instantiated
> two times then if I add another package the interceptor should be
> instantiated three times right? but it only gets instantiated two times max.
>
> The clarify the sample I created is a very simple app created from the
> blank war, I only added the bare minimum to reproduce the problem, to be
> exact init() wasn't called twice when I was using 2.1.8, if I recall
> correctly this behavior started on 2.3.8.
> So I want to confirm that this behavior is expected.
>
> Thanks
>
>
> On Wed, Apr 24, 2013 at 9:46 PM, Maurizio Cucchiara <mcucchi...@apache.org
> > wrote:
>
>> Yep, it makes sense definitely, otherwise there would not be way to share
>> a
>> single instance with different params.
>> Il giorno 24/apr/2013 15:31, "Dave Newton" <davelnew...@gmail.com> ha
>> scritto:
>>
>> > Definitely singleton-ish, although i thought there was an
>> > instance-per-package--I thought I had packages with the same interceptor
>> > configured in different ways, but I can't check at the moment.
>> >
>> > Dave
>> >
>> >
>> >
>> > On Wed, Apr 24, 2013 at 9:28 AM, Maurizio Cucchiara
>> > <mcucchi...@apache.org>wrote:
>> >
>> > > @Dave, I also could be wrong, but I remember that interceptors are
>> > > singletone (maybe there is a single instance per package).
>> > > @Steven looks like you're using Spring, if yes, could you check if you
>> > > experience the same behavior w/o it?
>> > > Il giorno 24/apr/2013 14:04, "Dave Newton" <davelnew...@gmail.com> ha
>> > > scritto:
>> > >
>> > > > I'm not sure I understand what you mean regarding using the
>> "include"
>> > > > element (i.e., precisely what you're doing) but I thought that each
>> > > package
>> > > > would have its own set of interceptors, meaning there would be two
>> > > > instances, hence init would be called twice.
>> > > >
>> > > > This would be trivial to determine by checking to see if it's the
>> same
>> > > > instance.
>> > > >
>> > > > I could be misremembering.
>> > > >
>> > > > Dave
>> > > >
>> > > >
>> > > >
>> > > > On Wed, Apr 24, 2013 at 7:52 AM, Steven Yang <kenshin...@gmail.com>
>> > > wrote:
>> > > >
>> > > > > I was using 2.1.8 and recently upgraded to 2.3.14.
>> > > > > And I realized that my interceptor got initialized twice and it
>> didnt
>> > > > > happen before.
>> > > > >
>> > > > > This happens when I declare a default package in struts.xml and
>> > include
>> > > > > other xml which have packages that extends my default package. But
>> > the
>> > > > > thing is no matter how many more xml I include the interceptor
>> will
>> > > only
>> > > > be
>> > > > > initialize one extra time.
>> > > > >
>> > > > > the following is my sample struts.xml
>> > > > >
>> > > > >  <package name="default" namespace="/" extends="struts-default">
>> > > > >
>> > > > > <interceptors>
>> > > > > <interceptor name="baseGeneral"
>> > > class="GeneralInterceptor"></interceptor>
>> > > > > <interceptor-stack name="biStack">
>> > > > > <interceptor-ref name="baseGeneral"/>
>> > > > > </interceptor-stack>
>> > > > > </interceptors>
>> > > > >         <default-action-ref name="index" />
>> > > > >
>> > > > >         <global-results>
>> > > > >             <result name="error">/error.jsp</result>
>> > > > >         </global-results>
>> > > > >
>> > > > >         <global-exception-mappings>
>> > > > >             <exception-mapping exception="java.lang.Exception"
>> > > > > result="error"/>
>> > > > >         </global-exception-mappings>
>> > > > >
>> > > > >         <action name="index">
>> > > > >             <result type="redirectAction">
>> > > > >                 <param name="actionName">HelloWorld</param>
>> > > > >                 <param name="namespace">/example</param>
>> > > > >             </result>
>> > > > >         </action>
>> > > > >     </package>
>> > > > >
>> > > > >     <include file="example.xml"/>
>> > > > >
>> > > > > my example.xml
>> > > > >
>> > > > >   <package name="example" namespace="/example" extends="default">
>> > > > >
>> > > > >         <action name="HelloWorld" class="example.HelloWorld">
>> > > > >             <result>/example/HelloWorld.jsp</result>
>> > > > >         </action>
>> > > > > </package>
>> > > > >
>> > > > > I traced the log and see the that my default package is been
>> > > initialized
>> > > > > twice and it seems that struts knows about it but it still called
>> > > init()
>> > > > on
>> > > > > my interceptor.
>> > > > > partial log:
>> > > > >
>> > > > > 2013-04-24 11:57:58,504 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Using default implementation of
>> FileManager
>> > > > > provided under name [system]: DefaultFileManager
>> > > > > 2013-04-24 11:57:58,505 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig
>> Name:default
>> > > > > namespace:/ parents:[{PackageConfig Name:struts-default namespace:
>> > > > > parents:[]}]}
>> > > > > GeneralInterceptor.init()
>> > > > > 2013-04-24 11:57:58,509 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded //index in 'default'
>> > > package:{ActionConfig
>> > > > > index () - action -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:30:30}
>> > > > > 2013-04-24 11:57:58,510 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig
>> Name:example
>> > > > > namespace:/example parents:[{PackageConfig Name:default
>> namespace:/
>> > > > > parents:[{PackageConfig Name:struts-default namespace:
>> > parents:[]}]}]}
>> > > > > 2013-04-24 11:57:58,513 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded /example/HelloWorld in 'example'
>> > > > > package:{ActionConfig HelloWorld (example.HelloWorld) - action -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:10:62}
>> > > > > 2013-04-24 11:57:58,514 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded /example/Login_* in 'example'
>> > > > > package:{ActionConfig Login_* (example.Login.{1}()) - action -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:14:67}
>> > > > > 2013-04-24 11:57:58,514 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded /example/* in 'example'
>> > > > > package:{ActionConfig * (example.ExampleSupport) - action -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:19:57}
>> > > > > 2013-04-24 11:57:58,515 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig
>> Name:default
>> > > > > namespace:/ parents:[{PackageConfig Name:struts-default namespace:
>> > > > > parents:[]}]}
>> > > > > GeneralInterceptor.init()
>> > > > > 2013-04-24 11:57:58,516 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - Loaded //index in 'default'
>> > > package:{ActionConfig
>> > > > > index () - action -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:30:30}
>> > > > > 2013-04-24 11:57:58,516 DEBUG
>> > > > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
>> > > > > (Slf4jLogger.java:69) - The package name 'default' is already been
>> > > loaded
>> > > > > by the same location and could be removed: package -
>> > > > >
>> file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:11:68
>> > > > >
>> > > > >
>> > > > > as you can see struts knows that "default" has been loaded before
>> > > however
>> > > > > my interceptor still prints out init message.
>> > > > >
>> > > > > If I remove the include or move the "default" package declaration
>> out
>> > > to
>> > > > > another file and use include to include it in struts.xml the
>> problem
>> > > goes
>> > > > > away.
>> > > > >
>> > > > > Is this behavior correct? or I am using something in the wrong
>> way?
>> > > > >
>> > > > > Thanks
>> > > > >
>> > > >
>> > > >
>> > > >
>> > > > --
>> > > > e: davelnew...@gmail.com
>> > > > m: 908-380-8699
>> > > > s: davelnewton_skype
>> > > > t: @dave_newton <https://twitter.com/dave_newton>
>> > > > b: Bucky Bits <http://buckybits.blogspot.com/>
>> > > > g: davelnewton <https://github.com/davelnewton>
>> > > > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>> > > >
>> > >
>> >
>> >
>> >
>> > --
>> > e: davelnew...@gmail.com
>> > m: 908-380-8699
>> > s: davelnewton_skype
>> > t: @dave_newton <https://twitter.com/dave_newton>
>> > b: Bucky Bits <http://buckybits.blogspot.com/>
>> > g: davelnewton <https://github.com/davelnewton>
>> > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>> >
>>
>
>

Reply via email to