啟動類代碼
package com.maven.demo; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableAutoConfiguration @ComponentScan("com.maven.demo") @MapperScan("com.maven.demo") @EnableTransactionManagement public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
發現路徑都是對的,但是就是掃描不到controller層
原因是maven多模塊項目忘記引入子模塊的maven依賴了,啟動類是一個子模塊,controller的代碼是另外一個子模塊,低級錯誤。