0

我正在使用弹簧 mvc。在每个控制器上,我想检查作为参数传递的 userId 是否有效。为此,我利用了 spring-aop,在方法调用之前,我读取了作为参数传递的 userId,并针对我的数据库进行了验证。问题是我的数据库(MongoDB 存储库)在方面是自动装配的。但是当尝试使用这个自动装配存储库时,我得到一个 NullPointerException。环顾四周后,我尝试将 factory-method="aspectOf" 放入方面的 bean 定义中,但出现以下错误 - “未找到匹配的工厂方法:工厂方法'aspectOf()'。检查指定的方法名称存在并且它是静态的。”

我的方面配置

<bean id="controllerAspect" class="com.xyz.aspect.ControllerLoggingAspect"/>
<aop:aspectj-autoproxy>
    <aop:include name="controllerAspect" />
</aop:aspectj-autoproxy>

Aspectj Maven 插件

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.7</version>
                <configuration>
                    <outxml>true</outxml>
                    <Xlint>warning</Xlint>
                    <verbose>true</verbose>
                    <source>1.6</source>
                    <target>1.6</target>
                    <complianceLevel>1.6</complianceLevel>
                </configuration>
                 <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <showWeaveInfo>true</showWeaveInfo>
                        </configuration>
                    </execution>
                 </executions>
            </plugin>

方面

@Configurable
@Aspect
public class ControllerLoggingAspect  {
@Autowired
private UsersRepository userRepository;

请帮帮我,我需要自动装配 mongodb 存储库。如果不是自动装配,我还能做什么?我什至在方面自动装配我的 mongo 存储库时是否正确?我已经看到以下无济于事的答案: https://stackoverflow.com/questions/25675151/springaspectj-ltw-autowired-causes-npe 注入的 bean 在 Aspect 中重置为 NULL

4

0 回答 0