Spring 4.3.4中的AOP依赖问题

问题描述 投票:0回答:3

我目前正在使用Spring 4.3.4来执行“简单方面示例程序”。我尝试使用XML和Annotation,但它给了我BeanCreationException错误。

创建名为'org.springframework.aop.config.internalAutoProxyCreator'的bean时出错

我添加了下面提到的依赖项:

  • 弹簧核心4.3.4
  • 春豆4.3.4
  • 春天语境4.3.4
  • 弹簧方面4.3.4

主要:

public class Main {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/sonyx64/spring/aop/config/Beans.xml");
        Camera camera = (Camera) context.getBean("camera");
        camera.snap();
        context.close();
    }}

相机类:

public class Camera {
    public void snap() {
        System.out.println("SNAP!");
    }
}

记录器类:

public class Logger {
    public void aboutToTakePhoto() {
        System.out.println("About To Take Photo");
    }
}

beans.xml中

<bean id="camera" class="com.sonyx64.spring.aop.Camera"></bean>
    <bean id="logger" class="com.sonyx64.spring.aop.Logger"></bean>
    <aop:config>
        <aop:pointcut expression="execution(void com.sonyx64.spring.aop.Camera.snap())"
            id="camerasnap" />
        <aop:aspect id="loggeraspect" ref="logger">
            <aop:before method="aboutToTakePhoto" pointcut-ref="camerasnap" />
        </aop:aspect>
    </aop:config>

请建议我一个适当的解决方案来处理这个例外。

spring aop spring-aop
3个回答
0
投票

我正在尝试相同的例子,我首先创建了maven项目,其次是方面编织器依赖项,我添加了1.8.8版本的aspectjweaver的排除,并包含了aspectjweaver 1.8.9版本,并且它工作正常。


-1
投票

问题在于maven存储库jar“aspectjweaver-1.8.9.jar”的特定版本。使用先前版本1.8.8运行解决了该问题。

POM.hml:

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <properties>
    <maven.target.source>1.8</maven.target.source>
    <maven.target.compiler>1.8</maven.target.compiler>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>4.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.8</version>
    </dependency>
  </dependencies>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.