Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I can use aop/aspect in jira plugin.

yunfeng wu July 1, 2014

My code is as follows:

spring.xml

<bean id="logInterceptor" class="apptools.jira.interceptor.LogInterceptor"></bean>  
    <aop:config proxy-target-class="true">  
        <aop:aspect ref="logInterceptor">  
        	<aop:pointcut id="logAspect" expression="execution(* apptools.jira.dao.impl.*(..))"/>
            <aop:around method="around" pointcut-ref="logAspect" />  
        </aop:aspect>  
    </aop:config>

atlassian-plugin.xml

<plugin-info>
		<description>${project.description}</description>
		<version>${project.version}</version>
		<vendor name="${project.organization.name}" url="${project.organization.url}" />
		<param name="plugin-icon">images/pluginIcon.png</param>
		<param name="plugin-logo">images/pluginLogo.png</param>
		<param name="emailFormat">html</param>
	  	<bundle-instructions>
	      <Import-Package>org.aspectj*;version="1.6.1",*</Import-Package>
	    </bundle-instructions>
	</plugin-info>
pom.xml
<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.6.1</version>
		</dependency>
LogInterceptor
package apptools.jira.interceptor;

 

import org.apache.log4j.Logger;

import org.aspectj.lang.ProceedingJoinPoint;

 

/**

 * 

 * @author yf.wu

 * 

 */

public class LogInterceptor {

 

static Logger logger = Logger.getLogger(LogInterceptor.class);

 

public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

StringBuffer sb = new StringBuffer();

try {

System.out.println(joinPoint.getSignature().getName() + " Start---------------------------------------");

logger.info(joinPoint.getSignature().getName() + " Dao Start---------------------------------------");

Object result = joinPoint.proceed();

System.out.println(joinPoint.getSignature().getName() + " Dao End---------------------------------------");

logger.info(joinPoint.getSignature().getName() + " Dao End---------------------------------------");

return result;

} catch (Exception e) {

sb.append("Method start:" + joinPoint.getTarget().getClass() + "." + joinPoint.getSignature().getName() + "()  ");

sb.append("Error info:[" + e.getMessage() + "]");

logger.error(sb.toString());

}

return "error";

}

}

when jira server start, no error occurs, but logInterceptor did not work. 

 

Thanks in advance.


5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Ali Cagatay November 22, 2017

Hello everyone,

Does anyone have solution for this?

Thanks,

A.

0 votes
Rafał Janiczak April 25, 2016

Hello guys

Did you successfully use aop in jira?

Rafał

0 votes
Tobias Löbermann February 21, 2016

Hi @yunfeng wu

do you solve your problems? I try to work with aop within my JIRA plugin too. I have the problem, that my aspect bean can't be created cause: 

Error creating bean with name 'myInterceptor' defined in URL [bundle://171.0:0/META-INF/spring/Sprint-Customer.xml]:

java.lang.NoClassDefFoundError: org/aspectj/lang/reflect/AjTypeSystem

 

Is it working for you? Thanks in advanced.

Tobias

0 votes
Alberto Expósito October 1, 2015

I need this

0 votes
Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 16, 2015

Hi, did you solve this?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events