java - How to configure AspectJ working with in Weblogic 12c in a war package -


i can't configure weblogic 12c work aspectj. reading posts have done try configure it, can't reach result. project works maven , aspectj maven plugin. configuration it's following:

pom.xml

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>co.example</groupid> <artifactid>pruebaaspectj</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging> <name>basicwebapp</name> <parent>     <groupid>com.oracle.weblogic.archetype</groupid>     <artifactid>wls-common</artifactid>     <version>12.1.3-0-0</version> </parent> <dependencies>     <dependency>         <groupid>javax</groupid>         <artifactid>javaee-web-api</artifactid>         <version>6.0</version>         <scope>provided</scope>     </dependency>     <dependency>         <groupid>org.aspectj</groupid>         <artifactid>aspectjrt</artifactid>         <version>1.8.7</version>     </dependency> </dependencies> <build>     <finalname>basicwebapp</finalname>     <plugins>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-compiler-plugin</artifactid>             <version>2.3.2</version>             <configuration>                 <source>1.8</source>                 <target>1.8</target>             </configuration>         </plugin>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-war-plugin</artifactid>             <version>2.1.1</version>             <configuration>                 <failonmissingwebxml>false</failonmissingwebxml>                 <target>1.8</target>                 <source>1.8</source>             </configuration>         </plugin>         <plugin>             <groupid>org.codehaus.mojo</groupid>             <artifactid>aspectj-maven-plugin</artifactid>             <version>1.8</version>             <configuration>                 <showweaveinfo>true</showweaveinfo>                 <source>${java.source-target.version}</source>                 <target>${java.source-target.version}</target>                 <xlint>ignore</xlint>                 <compliancelevel>${java.source-target.version}</compliancelevel>                 <encoding>utf-8</encoding>                 <verbose>true</verbose>                 <aspectdirectory>src/java/aspectos</aspectdirectory>                 <!--<sources>                     <source>                         <basedir>src/main/java</basedir>                         <includes>                             <include>**/*.aj</include>                             <include>**/*.java</include>                         </includes>                     </source>                 </sources>-->                 <outputdirectory>${project.reporting.outputdirectory}/aspectj-report</outputdirectory>              </configuration>             <executions>                 <execution>                     <!-- important -->                     <phase>process-sources</phase>                     <goals>                         <goal>compile</goal>                     </goals>                 </execution>             </executions>             <dependencies>                 <dependency>                     <groupid>org.aspectj</groupid>                     <artifactid>aspectjtools</artifactid>                     <version>${aspectj.version}</version>                 </dependency>                 <dependency>                     <groupid>org.aspectj</groupid>                     <artifactid>aspectjrt</artifactid>                     <version>1.8.7</version>                 </dependency>                 <dependency>                     <groupid>org.aspectj</groupid>                     <artifactid>aspectjweaver</artifactid>                     <version>1.8.7</version>                 </dependency>             </dependencies>         </plugin>     </plugins> </build> <properties>     <project.build.sourceencoding>utf-8</project.build.sourceencoding>     <java.source-target.version>1.8</java.source-target.version>     <aspectj.version>1.8.7</aspectj.version> </properties> 

my aspect

package aspectos;  public aspect logger { pointcut logger() : call(* co.example..*(..));  before() : logger() {     system.out.println("#### signatura: "+thisjoinpointstaticpart.getsignature());     boolean entro = false;     (int = 0; < thisjoinpoint.getargs().length; i++) {         if(!entro){             system.out.println("#### argumentos: ");             entro=true;         }         system.out.println("\t"+thisjoinpoint.getargs()[i].getclass().tostring());     }     system.out.println("#### target: "+thisjoinpoint.gettarget().getclass().tostring()); }  after() returning(object r): logger(){     if(r!=null){         system.out.println("#### objeto retornado: "+r.getclass().getsimplename());     } }  after() throwing(throwable e): logger(){     system.out.println("#### excepcion: "+e.getmessage()); } } 

so, when run mvn clean install error shown:

errors shown aspectj

i know spring has compatibility aspectj can't use it, need configuration shown above. if want me have code of example in repo in github:

https://github.com/afdecastro879/aspectjprueba

finally, i'm developing project using intellij idea ide.

thanks all

the aspect such looks bit long-winded, okay (except package name typo co.example instead of com.example in pointcut). recommend do, though, use standard maven directory layout instead of customising paths in aspectj maven plugin, because intellij idea plays nicely maven projects, being able auto-update idea project settings whenever change pom etc.

you should remove 2 parameters aspectj maven configuration:

<aspectdirectory>src/java/aspectos</aspectdirectory> <!-- ... --> <outputdirectory>${project.reporting.outputdirectory}/aspectj-report</outputdirectory> 

i cloned repo , fixed pom , few other things (typos in package names in pointcuts, committed binaries etc.) you. created pull request in order enable integrate changes repo. last, not least, added sample stand-alone application main method able test whole thing.

now maven says:

[info] --- aspectj-maven-plugin:1.8:compile (default) @ pruebaaspectj --- [info] showing ajc message detail messages of types: [error, warning, fail] [info] join point 'method-execution(java.lang.string com.example.accountbean.getname())' in type 'com.example.accountbean' (accountbean.java:29) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-execution(void com.example.accountbean.setname(java.lang.string))' in type 'com.example.accountbean' (accountbean.java:33) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-execution(float com.example.accountbean.getamount())' in type 'com.example.accountbean' (accountbean.java:37) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-execution(void com.example.accountbean.setamount(float))' in type 'com.example.accountbean' (accountbean.java:41) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-execution(java.lang.string com.example.accountbean.getmsg())' in type 'com.example.accountbean' (accountbean.java:45) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-execution(void com.example.accountbean.deposit())' in type 'com.example.accountbean' (accountbean.java:50) advised around advice 'com.example.aroundexample' (aroundexample.java:18) [info] join point 'method-call(void com.example.accountbean.setname(java.lang.string))' in type 'de.scrum_master.app.application' (application.java:8) advised before advice 'aspectos.logger' (logger.aj:9) [info] join point 'method-call(void com.example.accountbean.setname(java.lang.string))' in type 'de.scrum_master.app.application' (application.java:8) advised afterreturning advice 'aspectos.logger' (logger.aj:22) [info] join point 'method-call(void com.example.accountbean.setname(java.lang.string))' in type 'de.scrum_master.app.application' (application.java:8) advised afterthrowing advice 'aspectos.logger' (logger.aj:28) [info] join point 'method-call(void com.example.accountbean.setamount(float))' in type 'de.scrum_master.app.application' (application.java:9) advised before advice 'aspectos.logger' (logger.aj:9) [info] join point 'method-call(void com.example.accountbean.setamount(float))' in type 'de.scrum_master.app.application' (application.java:9) advised afterreturning advice 'aspectos.logger' (logger.aj:22) [info] join point 'method-call(void com.example.accountbean.setamount(float))' in type 'de.scrum_master.app.application' (application.java:9) advised afterthrowing advice 'aspectos.logger' (logger.aj:28) 

and sample application yields output:

#### signatura: void com.example.accountbean.setname(string) #### argumentos:      class java.lang.string #### target: class com.example.accountbean executing aspectj #### signatura: void com.example.accountbean.setamount(float) #### argumentos:      class java.lang.float #### target: class com.example.accountbean executing aspectj com.example.accountbean@1be6f5c3  process finished exit code 0 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -