code review updates

This commit is contained in:
2024-08-07 11:01:45 -04:00
parent 9581a4d9be
commit 0e0fb55289
4 changed files with 13 additions and 8 deletions

3
.gitignore vendored
View File

@@ -7,3 +7,6 @@ pom.xml.versionsBackup
.project .project
.classpath .classpath
# VSCode
.vscode

View File

@@ -6,7 +6,7 @@ This module provides AspectJ support to Alfresco Content Services.
### AspectJ vs AOP Alliance ### 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 ### AspectJ in Spring AOP
@@ -16,25 +16,27 @@ If you try to narrow it using `<aop:include>`, the problem persists. If you try
### AspectJ outside Spring AOP, but in Spring ### 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. 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` ### `@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 ```ini
inteligr8.mymodule.aspectj.basePackages=com.myco.alfresco.mymodule.aspect 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` ### `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. 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.

View File

@@ -27,7 +27,7 @@ import org.springframework.stereotype.Component;
public class AspectJSpringAdapter { public class AspectJSpringAdapter {
private final Logger logger = LoggerFactory.getLogger(AspectJSpringAdapter.class); private final Logger logger = LoggerFactory.getLogger(AspectJSpringAdapter.class);
private final String basePackagePropertySuffix = "aspectj.scanPackages"; private final String basePackagePropertySuffix = ".aspectj.scanPackages";
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;

View File

@@ -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 # e.g. mymodule.aspectj.scanPackages=com.myco.alfresco.mymodule