Questions tagged [aspect]

An aspect is a module implemented in an Aspect-Oriented Programming language that contains code for a cross-cutting concern, like logging or security. For questions about the aspect ratio of images, use the aspect-ratio tag.

This tag is for Aspect-Oriented Programming. For questions and answers about the aspect ratio of images, please use the tag.

A feature of a program, like logging, is usually spread throughout a program and is not related to that program's main function. Such a feature is called a cross-cutting concern. The aim of aspect-oriented software development (AOSD) (also called aspect-oriented programming or AOP) is to move a cross-cutting concerns into an aspect. This is called refactoring the code.

In AOSD, aspects are written separately from the main application, which can be written in any standard OOP language. An AOP compiler, like AspectJ, compiles the AOP code and object-oriented programming (OOP) code together in a process called weaving.

AOP is often used to enhance legacy applications or 3rd party libraries when the original source code is not available. It is also used to overcome the main weakness of OOP by collecting the cross-cutting concerns into aspects.

Wikis:

See also:

433 questions
133
votes
13 answers

How to profile methods in Scala?

What is a standard way of profiling Scala method calls? What I need are hooks around a method, using which I can use to start and stop Timers. In Java I use aspect programming, aspectJ, to define the methods to be profiled and inject bytecode to…
sheki
  • 8,991
  • 13
  • 50
  • 69
71
votes
1 answer

Getting UndeclaredThrowableException instead of my own exception

I have the following code public Object handlePermission(ProceedingJoinPoint joinPoint, RequirePermission permission) throws AccessException, Throwable { System.out.println("Permission = " + permission.value()); if…
user373201
  • 10,945
  • 34
  • 112
  • 168
23
votes
4 answers

How to specify single pointcut for multiple packages

I am using Aspect for logging activities in my spring mvc based application. I am using @controller annotations to define any controller in my application. I have two different controller in two different package say com.package1 contains…
Ketan
  • 2,612
  • 5
  • 31
  • 44
20
votes
1 answer

What is the difference between a Decorator, Attribute, Aspect, and Trait?

From the standpoint of pure computer science (or perhaps computational linguisticis), I would like to know the difference between the words: Decorator Attribute Aspect Trait Various Languages utilize these words and functionality in difference…
Darkenor
  • 4,349
  • 8
  • 40
  • 67
16
votes
1 answer

Spring Boot Logger Aspects

I'm having problems getting my logging aspect to log information when methods from classes of a particular package are accessed. In other words, "no" logging occurs. I even got desperate and added System.out.println statements, with no luck. All…
Rick
  • 699
  • 1
  • 6
  • 17
14
votes
8 answers

Get all exceptions in Java and send them remotely

I have a huge Java application. I want to intercept all Java Exceptions and send them by e-mail. I can't add everywhere code for sending the code via try-catch so is it possible to use for example Aspect to intercept the exception into low level…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
9
votes
2 answers

How to make an AspectJ Aspect work in a Gradle project?

I am using the following sample code to understand AspectJ: public class Account { int balance = 20; public boolean withdraw(int amount) { if (balance < amount) { return false; } balance = balance -…
F. K.
  • 694
  • 3
  • 9
  • 23
7
votes
2 answers

How run aspect in Spring without xml?

How to run an aspect in Java. How to run an aspect in Spring using annotations, without xml file? Many other tutorials using xml file for configuration ascpect.
Stack Over
  • 143
  • 2
  • 12
7
votes
2 answers

C# 7 Local Functions: are attributes / aspects allowed?

C# 7 introduced local functions (which is great!). Suppose I have the following code: using System; using PostSharp.Aspects; namespace AspectCS7 { class Program { private static void Main() …
user2341923
  • 4,537
  • 6
  • 30
  • 44
7
votes
1 answer

BeanNotOfRequiredTypeException but was actually of type $Proxy

I need help with a problem with Spring and proxy. org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'fooAPIService' must be of type [com.foo.clientapi.service.FooAPIService], but was actually of type…
MaximeF
  • 4,913
  • 4
  • 37
  • 51
7
votes
2 answers

Is it possible to create a JAR with an aspect that is automatically applied to classes in client project?

I want to have a JAR with an aspect that intercepts all method calls, e.g. @Aspect public class CoolAspect { @Pointcut("execution(public * *(..))") public void anyPublicMethod() { } @Before("anyPublicMethod()") public void…
Parobay
  • 2,549
  • 3
  • 24
  • 36
6
votes
2 answers

castle windsor interceptor on method that is calling by another method

Interceptor public class CachingInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { // code comes here.... } } Business Layer public class Business : IBusiness { public void Add(string a) …
6
votes
1 answer

Spring(Java): Aspect is not triggered in non linear class hierarchy

When class hierarchy is not linear, aspect is not triggered when defined on base interface. The most interesting: when adding delegating implementation (see last code block) to the parent class of the implementation, the test becomes Green (Aspect…
Sergej Werfel
  • 1,335
  • 2
  • 14
  • 25
6
votes
1 answer

How implements Spring Bootstrap and Aspect?

I try to configure a logging aspect but I don't understand how it's works. I have a spring web mvc application. Consider this : a package of config classes with LoggingConfiguration : import org.springframework.context.annotation.Bean; import…
Jonathan Lebrun
  • 1,462
  • 3
  • 20
  • 42
6
votes
1 answer

How to avoid hitting pointcut twice when the cut is on a superclass, but a derived class overrides?

It's tough to make a concise title for this. Anyway, imagine I have a parent class: public class Shape { public Dimensions getDimensions() { // Does some generic stuff. } } I have a derived class from it that…
Depressio
  • 1,329
  • 2
  • 20
  • 39
1
2 3
28 29