问题
拆包之后,发现项目启动时报错Consider defining a bean of type,这个问题主要是因为项目拆包后,在原有的引用项目中无法找到对应的包的路径。
解决
让原来引用的项目可以找到资源的路径就可以了;或者将启动类 放到一个包拆成两个包后的平行路径中(因为之前只有一个包,启动类是放在包里,拆包后有两个包,想要扫描到两个包,就得将其移到 平行包的路径,很简单,这里不详细说啦)
具体执行步骤
在项目的Application启动文件里,使用@MapperScan注解,把当前的路径引用进去就可以了。
解决方法
(实际用的时候根据自己的包路径进行修改)
1.1@Mapper注解
作用:在接口类上添加了@Mapper,在编译之后会生成相应的接口实现类
添加位置:接口类上面
@Mapper
public interface UserDAO {
//代码
}
如果想要每个接口都要变成实现类,那么需要在每个接口类上加上@Mapper注解,比较麻烦,解决这个问题用@MapperScan
2.1使用@MapperScan单个注解包
MapperScan作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
添加位置:是在Springboot启动类上面添加,添加@MapperScan(“com.peach.mapper”)注解以后,com.peach.mapper包下面的接口类,在编译之后都会生成相应的实现类
@SpringBootApplication
@MapperScan(basePackages = "com.peach.mapper")
public class SystemApplication {
public static void main(String[] args
{SpringApplication.run(KehuApplication.class, args);
}
}
2.2使用@MapperScan注解多个包
@SpringBootApplication
@MapperScan({"org.spring.ext","org.spring.blade"})
public class SystemApplication {
public class App {
public static void main(String[] args) {SpringApplication.run(App.class, args);}
}
注解后再启动就没有报错了,如果有帮助到你,那就太好了!