Announcement Announcement Module
Collapse
No announcement yet.
Loggin AOP problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loggin AOP problem

    I have try to log with AOP but nothing seems to work it's like no logging want to appear i've tried from System.out.println to the INFO logger nothign!!!

    Code:
    <?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:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <import resource="applicationContext.xml"/>
        <aop:config>
            <aop:aspect ref="LoggingAspect">
                <aop:pointcut id="myCutLogging"
                              expression="execution ( * org.ksique.ui.support.*.*(..) )"/>
                <aop:around pointcut-ref="myCutLogging" method="log"/>
            </aop:aspect>
    
        </aop:config>
    
        <bean id="LoggingAspect" class="org.ksique.aop.LogginAspect" />
    
    </beans>

  • #2
    Try to use your setup with the single config '*.xml' file (i.e. inline 'applicationContext.xml' content in place of '<import resource="applicationContext.xml"/>')

    Comment


    • #3
      Try that but nothing

      I Tried that but still the same problem. BTW i logged directly on a method from a class in ui.support.* and log pretty fine but i cannot get it done with AOP.

      Another small detail i am using IceFaces but i dont think that would matter to much right?

      Comment


      • #4
        Originally posted by necronet View Post
        Another small detail i am using IceFaces but i dont think that would matter to much right?
        Not sure about that. General spring aop idea is to create aop proxy and provide it to the client instead of the target 'raw' bean. Every time proxy method is called it performs aop processing if necessary and delegates to the target 'raw' bean.

        That may be the case that IceFaces usage interferes with aop proxies construction and no proxy is created. Another possible case is that the proxies are created but they are not called, i.e. the call is performed on a 'raw' instance etc.

        I think that the best way to find the problem is to emulate it as a minimal but complete standalone example, post it here and ask for help on concrete example.

        Comment


        • #5
          Thank you

          This is a little sample of what i want to do but i haven't being able to get it work

          i attached the src and web.

          Comment


          • #6
            Sorry, but your example is incomplete - it doesn't contain information about libraries and versions that should be used with it.

            I tried it with tomcat 6.0.20 and the following key dependencies:
            HTML Code:
                    <dependency>
                        <groupId>myfaces</groupId>
                        <artifactId>myfaces-jsf-api</artifactId>
                        <version>1.0.9</version>
                    </dependency>
            
                    <dependency>
                        <groupId>org.apache.myfaces.core</groupId>
                        <artifactId>myfaces-impl</artifactId>
                        <version>1.2.7</version>
                    </dependency>
            
                    <dependency>
                        <groupId>org.icefaces</groupId>
                        <artifactId>icefaces</artifactId>
                        <version>1.8.2</version>
                    </dependency>
            
                    <dependency>
                        <groupId>com.sun.facelets</groupId>
                        <artifactId>jsf-facelets</artifactId>
                        <version>1.1.14</version>
                    </dependency>
            However, I'm getting the following on Tomcat startup:
            Code:
            Dec 14, 2009 4:18:19 PM org.apache.catalina.core.StandardContext listenerStart
            SEVERE: Exception sending context initialized event to listener instance of class org.apache.myfaces.webapp.StartupServletContextListener
            java.lang.LinkageError: loader constraints violated when linking javax/el/ELResolver class
            	at org.apache.myfaces.webapp.Jsp21FacesInitializer.configureResolverForJSP(Jsp21FacesInitializer.java:122)
            	at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:76)
            	at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:88)
            	at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:72)
            	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
            	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
            	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
            	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
            	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
            	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
            	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
            	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
            	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
            	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
            	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
            	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
            	at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
            	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
            	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
            	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
            	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
            	at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            	at java.lang.reflect.Method.invoke(Method.java:585)
            	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
            	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
            I can check your example if it's really standalone (no servlet-container involved) or if you provide complete example configuration (maven pom.xml is fine for that).

            Comment


            • #7
              Maven i tried but no success

              i am not that into maven i try to make the sample but i honestly did not get the whole maven idea!!!...... i'm stuck with my own i use:

              IceFace core
              IceFace support
              IceFace Facelest support
              Spring
              Spring-AOP

              Comment


              • #8
                Btw

                By the way i am using Glassfish V2

                Comment


                • #9
                  Originally posted by necronet View Post
                  i am not that into maven i try to make the sample but i honestly did not get the whole maven idea!!!...... i'm stuck with my own i use:

                  IceFace core
                  IceFace support
                  IceFace Facelest support
                  Spring
                  Spring-AOP
                  I hope you realize that provided information doesn't allow to check your use-case at the local environment

                  I mean that I should try to setup the environment, try various versions of the libraries you mentioned to get your example working. It's not attractive enough to proceed

                  Comment


                  • #10
                    Thank you so much another try

                    i just create this .WAR with the source inside so you can run it easier. It's much simpler cuz i did not added the Facelet Libreries.

                    WAR link

                    PD. i really aprecciate your effort!!

                    Comment


                    • #11
                      I succeeded in running your example eventually.

                      Solution:
                      1. Define target managed bean at the spring config (add the following declaration to it - '<bean id="testBean" class="com.test.BeanTest"/>');
                      2. Add 'cglib' library to your applications dependencies (necessary for creating aop proxy for the target bean);
                      3. Use 'SpringBeanVariableResolver' instead of 'DelegatingVariableResolver' at the 'faces-config.xml':
                        HTML Code:
                        <application>
                            <view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
                            <variable-resolver>org.springframework.web.jsf.SpringBeanVariableResolver</variable-resolver>
                        </application>

                      Comment


                      • #12
                        Thank you it work

                        Well it work i just have one question why i couldnt do it with my bean on faces-config.xml isnt wrong to create two beans with the same name???

                        Spring context
                        Code:
                        <bean id="testBean" class="com.test.BeanTest"/>
                        Faces config
                        Code:
                         <managed-bean>
                                       <managed-bean-name>testBean</managed-bean-name>
                                       <managed-bean-class>com.test.BeanTest</managed-bean-class>
                                       <managed-bean-scope>request</managed-bean-scope>
                        </managed-bean>
                        Or Spring has a way to keep both object with the same reference??
                        Last edited by necronet; Dec 16th, 2009, 01:56 AM. Reason: lack of code tags

                        Comment


                        • #13
                          Dude, I've never worked either with jsf or spring jsf at all

                          All I can do here is to provide you a guide line on how I sorted out your problem:
                          1. Started the application at your initial configuration;
                          2. Checked call stack when 'BeanTest.myMetodo()' was called and detected that spring was not involved to the processing;
                          3. Read javadoc for the spring class that was used at your config - DelegatingVariableResolver:
                            SF 1.1 VariableResolver that first delegates to the original resolver of the underlying JSF implementation (for resolving managed-bean objects as defined in faces-config.xml as well as well-known implicit EL attributes), then to the Spring root WebApplicationContext (for resolving Spring beans).
                          4. I know spring aop principles and realize that aop logic is involved only if aop proxy is called instead of the 'raw' bean, so, I became suspicious for the message 'first delegates to the original resolver of the underlying JSF implementation';
                          5. The javadoc also mentions JSF 1.1 VariableResolver, so, I checked what spring implementations of it are available over than DelegatingVariableResolver;
                          6. I found SpringBeanVariableResolver that states the following:
                            This is a subclass of the JSF 1.1 DelegatingVariableResolver, letting Spring bean definitions override other attributes of the same name.
                            So, it looked like it tries to use the beans from spring context whenever possible;
                          7. I checked DelegatingVariableResolver javadoc mentions jsf config snippet where jsf and spring stuffs are linked via spring bean name;
                          8. I tried to combine all of above together and checked that it works as expected now;

                          You can find all of the further jsf-related answers by yourself using the similar algorithm. Spring provides an excellent documentation (either reference or javadoc). Just don't be afraid to work with it.

                          One more important note - I believe that it's very-very-very-very-...-very important to avoid leaky abstractions, i.e. should have an understanding either of spring or jsf principles in order to be able to work with them at good level. I have a good spring knowledge and some basic understanding of JSF ideas, that helped me to find out the problem.

                          Comment


                          • #14
                            i apreciate it then thank you

                            Comment

                            Working...
                            X