新建的SpringBoot项目无法扫描到Dao层,
控制台输出信息如下:
/Library/Java/JavaVirtualMachines/jdk-11.0.17.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63596,suspend=y,server=n -javaagent:/Users/zjwu/Library/Caches/JetBrains/IdeaIC2022.2/captureAgent/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath /Users/zjwu/Documents/personal/backend/catalpa-authorization-backend/target/classes:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-starter/2.5.12/spring-boot-starter-2.5.12.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot/2.5.12/spring-boot-2.5.12.jar:/Users/zjwu/.m2/repository/org/springframework/spring-context/5.3.18/spring-context-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.5.12/spring-boot-autoconfigure-2.5.12.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.5.12/spring-boot-starter-logging-2.5.12.jar:/Users/zjwu/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar:/Users/zjwu/.m2/repository/ch/qos/logback/logback-core/1.2.11/logback-core-1.2.11.jar:/Users/zjwu/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.17.2/log4j-to-slf4j-2.17.2.jar:/Users/zjwu/.m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar:/Users/zjwu/.m2/repository/org/slf4j/jul-to-slf4j/1.7.36/jul-to-slf4j-1.7.36.jar:/Users/zjwu/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/zjwu/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/spring-jcl/5.3.18/spring-jcl-5.3.18.jar:/Users/zjwu/.m2/repository/org/yaml/snakeyaml/1.28/snakeyaml-1.28.jar:/Users/zjwu/.m2/repository/net/bytebuddy/byte-buddy/1.10.22/byte-buddy-1.10.22.jar:/Users/zjwu/.m2/repository/org/springframework/spring-web/5.3.18/spring-web-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/spring-beans/5.3.18/spring-beans-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.5.12/spring-boot-starter-web-2.5.12.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.5.12/spring-boot-starter-json-2.5.12.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.6.1/jackson-databind-2.12.6.1.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.6/jackson-core-2.12.6.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.12.6/jackson-datatype-jdk8-2.12.6.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.6/jackson-datatype-jsr310-2.12.6.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.12.6/jackson-module-parameter-names-2.12.6.jar:/Users/zjwu/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.5.12/spring-boot-starter-tomcat-2.5.12.jar:/Users/zjwu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.60/tomcat-embed-core-9.0.60.jar:/Users/zjwu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.60/tomcat-embed-el-9.0.60.jar:/Users/zjwu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.60/tomcat-embed-websocket-9.0.60.jar:/Users/zjwu/.m2/repository/org/springframework/spring-webmvc/5.3.18/spring-webmvc-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/spring-aop/5.3.18/spring-aop-5.3.18.jar:/Users/zjwu/.m2/repository/org/springframework/spring-expression/5.3.18/spring-expression-5.3.18.jar:/Users/zjwu/.m2/repository/org/mybatis/generator/mybatis-generator-core/1.3.5/mybatis-generator-core-1.3.5.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-swagger2/2.9.2/springfox-swagger2-2.9.2.jar:/Users/zjwu/.m2/repository/io/swagger/swagger-annotations/1.5.20/swagger-annotations-1.5.20.jar:/Users/zjwu/.m2/repository/io/swagger/swagger-models/1.5.20/swagger-models-1.5.20.jar:/Users/zjwu/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.6/jackson-annotations-2.12.6.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-spi/2.9.2/springfox-spi-2.9.2.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-core/2.9.2/springfox-core-2.9.2.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-schema/2.9.2/springfox-schema-2.9.2.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-swagger-common/2.9.2/springfox-swagger-common-2.9.2.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar:/Users/zjwu/.m2/repository/com/google/guava/guava/20.0/guava-20.0.jar:/Users/zjwu/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/zjwu/.m2/repository/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar:/Users/zjwu/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar:/Users/zjwu/.m2/repository/org/springframework/plugin/spring-plugin-metadata/1.2.0.RELEASE/spring-plugin-metadata-1.2.0.RELEASE.jar:/Users/zjwu/.m2/repository/org/mapstruct/mapstruct/1.2.0.Final/mapstruct-1.2.0.Final.jar:/Users/zjwu/.m2/repository/io/springfox/springfox-swagger-ui/2.9.2/springfox-swagger-ui-2.9.2.jar:/Users/zjwu/.m2/repository/com/alibaba/fastjson/2.0.8.graal/fastjson-2.0.8.graal.jar:/Users/zjwu/.m2/repository/com/alibaba/fastjson2/fastjson2-extension/2.0.8.graal/fastjson2-extension-2.0.8.graal.jar:/Users/zjwu/.m2/repository/com/alibaba/fastjson2/fastjson2/2.0.8.graal/fastjson2-2.0.8.graal.jar:/Users/zjwu/.m2/repository/org/mybatis/mybatis/3.5.10/mybatis-3.5.10.jar:/Users/zjwu/.m2/repository/org/springframework/spring-tx/5.2.15.RELEASE/spring-tx-5.2.15.RELEASE.jar:/Users/zjwu/.m2/repository/com/github/pagehelper/pagehelper/5.3.0/pagehelper-5.3.0.jar:/Users/zjwu/.m2/repository/com/github/jsqlparser/jsqlparser/4.2/jsqlparser-4.2.jar:/Users/zjwu/.m2/repository/joda-time/joda-time/2.10/joda-time-2.10.jar:/Users/zjwu/.m2/repository/javax/persistence/javax.persistence-api/2.2/javax.persistence-api-2.2.jar:/Users/zjwu/.m2/repository/tk/mybatis/mapper-core/1.1.5/mapper-core-1.1.5.jar:/Users/zjwu/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/Users/zjwu/.m2/repository/tk/mybatis/mapper-extra/1.1.5/mapper-extra-1.1.5.jar:/Users/zjwu/.m2/repository/tk/mybatis/mapper-base/1.1.5/mapper-base-1.1.5.jar:/Users/zjwu/.m2/repository/org/mybatis/mybatis-spring/2.0.7/mybatis-spring-2.0.7.jar:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar com.catalpa.authorization.AuthorizationApplication
已连接到目标 VM, 地址: ''127.0.0.1:63596',传输: '套接字''
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.12)
2023-02-25 16:22:14.388 INFO 12842 --- [ main] c.c.a.AuthorizationApplication : Starting AuthorizationApplication using Java 11.0.17 on MacBook-Pro-2.local with PID 12842 (/Users/zjwu/Documents/personal/backend/catalpa-authorization-backend/target/classes started by zjwu in /Users/zjwu/Documents/personal/backend/catalpa-authorization-backend)
2023-02-25 16:22:14.392 INFO 12842 --- [ main] c.c.a.AuthorizationApplication : The following 1 profile is active: "default"
2023-02-25 16:22:15.390 INFO 12842 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8094 (http)
2023-02-25 16:22:15.400 INFO 12842 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-02-25 16:22:15.401 INFO 12842 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2023-02-25 16:22:15.497 INFO 12842 --- [ main] o.a.c.c.C.[.[.[/authorization-default] : Initializing Spring embedded WebApplicationContext
2023-02-25 16:22:15.497 INFO 12842 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1040 ms
2023-02-25 16:22:15.570 WARN 12842 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.catalpa.authorization.dao.SysUserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
2023-02-25 16:22:15.573 INFO 12842 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-02-25 16:22:15.584 INFO 12842 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-02-25 16:22:15.600 ERROR 12842 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'com.catalpa.authorization.dao.SysUserDao' that could not be found.
Action:
Consider defining a bean of type 'com.catalpa.authorization.dao.SysUserDao' in your configuration.
与目标 VM 断开连接, 地址为: ''127.0.0.1:63596',传输: '套接字''
进程已结束,退出代码1
application代码如下:
package com.catalpa.authorization;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
/**
* @author zjwu
*/
@ComponentScan(basePackages = {
"com.catalpa.authorization.**"
})
@SpringBootApplication
public class AuthorizationApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AuthorizationApplication.class);
}
public static void main(String[] args) {
new AuthorizationApplication().configure(new SpringApplicationBuilder(AuthorizationApplication.class)).run(args);
}
}
controller类如下:
package com.catalpa.authorization.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author zjwu
*/
@RestController
@RequestMapping(value = "/service/dept")
@Api(tags = "测试")
public class SysDeptController {
@ApiOperation(value = "测试接口")
@GetMapping("/test")
public String getTest() {
return "hello world";
}
}
service层如下:
package com.catalpa.authorization.service;
import com.catalpa.authorization.bean.SysUser;
import com.catalpa.authorization.utils.IBaseService;
/**
* @author zjwu
*/
public interface ISysUserService extends IBaseService<SysUser> {
}
package com.catalpa.authorization.service.impl;
import com.catalpa.authorization.bean.SysUser;
import com.catalpa.authorization.dao.SysUserDao;
import com.catalpa.authorization.service.ISysUserService;
import com.catalpa.authorization.utils.BaseMapper;
import com.catalpa.authorization.utils.BaseServiceImpl;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @author zjwu
*/
@Repository
@Transactional(rollbackFor = Exception.class)
public class SysUserImpl extends BaseServiceImpl<SysUser> implements ISysUserService {
@Resource
private SysUserDao sysUserDao;
@Override
public BaseMapper<SysUser> getDao() {
return this.sysUserDao;
}
}
Dao层如下:
package com.catalpa.authorization.dao;
import com.catalpa.authorization.bean.SysUser;
import com.catalpa.authorization.utils.BaseMapper;
/**
* @author zjwu
*/
public interface SysUserDao extends BaseMapper<SysUser> {
}