diff --git a/.gitignore b/.gitignore index 620a11b..dacab77 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ pom.xml.versionsBackup .project .classpath +# VSCode +.vscode + diff --git a/README.md b/README.md index 36479c3..1d65916 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This module provides AspectJ support to Alfresco Content Services. ### AspectJ vs AOP Alliance -Alfresco Content Services rests on top of the Spring Framework. It is an older version and the code was original written before 2010. Although it uses the principles behind AspectJ, it does not use the modern implementation of it. It instead is using the AOP Alliance API, a stripped down version of AspectJ (`aspectjrt`), and `spring-aop`. Although these libraries seem to support annotation-based AspectJ implementations, you will quickly run into problems. +Alfresco Content Services rests on top of the Spring Framework. It is an older version and the code was originally written before 2010. Although it uses the principles behind AspectJ, it does not use the modern implementation of it. It instead is using the AOP Alliance API, a stripped down version of AspectJ (`aspectjrt`), and `spring-aop`. Although these libraries seem to support annotation-based AspectJ implementations, you will quickly run into problems. ### AspectJ in Spring AOP @@ -16,25 +16,27 @@ If you try to narrow it using ``, the problem persists. If you try ### AspectJ outside Spring AOP, but in Spring -So this module enables AspectJ as if you were not use Spring. It then assumes your `@Aspect` objects are Spring beans and loads them dynamically. This prevents conflicts with ACS libraries while giving you the ability to use AspectJ annotations. +So this module enables AspectJ as if you were not using Spring. It then assumes your `@Aspect` objects are Spring beans and loads them dynamically. This prevents conflicts with ACS libraries while giving you the ability to use AspectJ annotations. -## Using +## How? This library will handle nearly all the requirements to get AspectJ working in ACS. The following are the exceptions and notes you need to be aware of. ### `@Aspect` -You can use the `@Aspect` annotation as you would think. However, you cannot add a `@Component` or similar annotation to the class. The class must NOT be defined as a Spring bean. We need to let AspectJ instantiate the class; not Spring. This module will side-load the instance as a Spring bean, including any use of @PostConstruct or @Autowired as one would expect. +You can use the `@Aspect` annotation as you would think. However, you cannot add a `@Component` or similar annotation to the class. The class must NOT be defined as a Spring bean. We need to let AspectJ instantiate the class; not Spring. This module will side-load the instance as a Spring bean, including any use of @PostConstruct, @Autowired, and @Value as one would expect. -You will also need to specify the base packages to scan for `@Aspect` classes. You can do that with any unique property in `alfresco-global.properties` (environment or module) or in the Java `-D` arguments. Here is an example: +You will also need to specify the base packages to scan for `@Aspect` classes and `@`. You can do that with any unique property in `alfresco-global.properties` (environment or module) or in the Java `-D` arguments. Here is an example: ```ini inteligr8.mymodule.aspectj.basePackages=com.myco.alfresco.mymodule.aspect ``` +Each package must have its own unique property with the suffix `.aspectj.basePackages`. It does **not** support a comma-delimited list of packages. + ### `aop.xml` -AspectJ without Spring AOP requires you to define your aspects. This module includes an `aop.xml` that deals with excluding ACS libraries. You just need to define your aspects and maybe exclude some more libraries to prevent them from being picked up. +AspectJ without Spring AOP requires you to define your aspects. This is a requirement of Spring to work properly with AspectJ. It is loaded by the JVM agent (super-early), so it cannot be dynamic. This module includes an `aop.xml` that deals with excluding ACS libraries. You just need to define your aspects and maybe exclude some more libraries to prevent them from being picked up. Create a file in your `src/main/resources` or similar path, called: `META-INF/aop.xml`. It should have something like the following contents. You cannot use wildcards to capture your aspects. diff --git a/src/main/java/com/inteligr8/alfresco/aspectj/AspectJSpringAdapter.java b/src/main/java/com/inteligr8/alfresco/aspectj/AspectJSpringAdapter.java index 2fc9434..73c65f0 100644 --- a/src/main/java/com/inteligr8/alfresco/aspectj/AspectJSpringAdapter.java +++ b/src/main/java/com/inteligr8/alfresco/aspectj/AspectJSpringAdapter.java @@ -27,7 +27,7 @@ import org.springframework.stereotype.Component; public class AspectJSpringAdapter { private final Logger logger = LoggerFactory.getLogger(AspectJSpringAdapter.class); - private final String basePackagePropertySuffix = "aspectj.scanPackages"; + private final String basePackagePropertySuffix = ".aspectj.scanPackages"; @Autowired private ApplicationContext applicationContext; diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.aspectj-platform-module/alfresco-global.properties b/src/main/resources/alfresco/module/com.inteligr8.alfresco.aspectj-platform-module/alfresco-global.properties index 6f97fa3..9a32d5a 100644 --- a/src/main/resources/alfresco/module/com.inteligr8.alfresco.aspectj-platform-module/alfresco-global.properties +++ b/src/main/resources/alfresco/module/com.inteligr8.alfresco.aspectj-platform-module/alfresco-global.properties @@ -1,3 +1,3 @@ -# To scan Java packages, add a unique property with the suffix: `aspectj.scanPackages` +# To scan Java packages, add a unique property with the suffix: `.aspectj.scanPackages` # e.g. mymodule.aspectj.scanPackages=com.myco.alfresco.mymodule