【解决问题】spring@Aspect注解无法引入

问题:

spring引入@Aspect注解始终爆红,无法引入:

排查:

步骤1:

查看依赖包:

经过查看已经导入,没有问题

步骤2:

发现导入的依赖多了一个<scope>runtime</scope>这个:

<scope>runtime</scope>

意思:runtime 是运行的意思。指的是直接在运行时所需要的包,而非在编译时等时候需要的包

步骤3:

去掉<scope>runtime</scope>

问题解决

思考:

  1. <scope>官方文档解释

英文原文摘录出来如下:

The scope of the dependency - compile, runtime, test, system, and provided. Used to calculate the various classpaths used for compilation, testing, and so on. It also assists in determining which artifacts to include in a distribution of this project. For more information, see the dependency mechanism. The default scope is compile.

默认是编译的

compile,runtime看下官网原文解释:

  • compile
    This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

  • runtime
    This scope indicates that the dependency is not required for compilation, but is for execution. Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath.

这个就清晰了,runtime这个是在运行及测试路径中使用的

  1. 官方依赖为啥会直接添加<scope>runtime</scope>呢?

这个真是个大坑呀,只不过不太明白官方为啥添加这个

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要使用Spring Framework,需要在项目的pom.xml文件中引入以下坐标: ``` <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> ``` 其中`${spring.version}`是Spring框架的版本号。 Spring的IOC(Inverse of Control)实现原理是通过BeanFactory和ApplicationContext两个核心接口实现的。BeanFactory是Spring的核心接口,用于管理对象的创建及依赖关系的维护。ApplicationContext是BeanFactory的一个扩展,提供了更多的功能,如事件传播、国际化、资源载入等。 Spring的AOP(Aspect Oriented Programming)实现原理是基于代理模式的。Spring AOP采用动态代理技术,对目标对象进行增强,实现横切关注点的统一处理。具体实现方式可以是JDK动态代理或CGLIB动态代理。 Spring的IOC和AOP可以解决软件开发过程中的诸多问题。IOC通过将对象的创建及依赖关系的维护交给Spring容器,降低了组件之间的耦合度,提高了代码的可维护性和可扩展性。AOP通过对横切关注点的统一处理,减少了重复代码的出现,提高了代码的复用性和可读性。 使用Spring注解方式,可以通过以下步骤实现: 1. 在配置类上添加`@Configuration`注解,表示该类为Spring的配置类。 2. 在配置类上添加`@ComponentScan`注解,指定需要扫描的包路径。 3. 在需要注入的对象上添加`@Component`注解,表示该类为Spring的组件。 4. 在需要注入的属性上添加`@Autowired`注解,表示该属性需要自动注入。 例如,以下代码演示了如何通过纯注解方式实现一个简单的UserService类: ```java @Component public class UserService { @Autowired private UserDao userDao; //... } @Configuration @ComponentScan(basePackages = "com.example") public class AppConfig { //... } public class UserDao { //... } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值