Java spring启动编译找不到符号componentscan

Java spring启动编译找不到符号componentscan,java,spring,spring-boot,aws-lambda,Java,Spring,Spring Boot,Aws Lambda,我在我的小型spring boot项目中发现了符号组件扫描错误。知道我哪里出错了吗 基类: @ComponentScan("com.example.test.lambda") @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringAppli

我在我的小型spring boot项目中发现了符号组件扫描错误。知道我哪里出错了吗

基类:

@ComponentScan("com.example.test.lambda")
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-boot-lambda: Compilation failure
[ERROR] spring-boot-lambda-test-jenkins/lambda-service/spring-boot-lambda/src/main/java/com/example/test/lambda/Application.java:[7,2] cannot find symbol
[ERROR]   symbol: class ComponentScan
配置类

@Configuration
@EnableWebMvc
@Profile("lambda")
public class Config {

    
    @Bean
    public HandlerMapping handlerMapping() {
        return new RequestMappingHandlerMapping();
    }

    
    @Bean
    public HandlerAdapter handlerAdapter() {
        return new RequestMappingHandlerAdapter();
    }

    
    @Bean
    public HandlerExceptionResolver handlerExceptionResolver() {
        return new HandlerExceptionResolver() {

            @Override
            public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
                return null;
            }
        };
    }

}
依赖关系树:

@ComponentScan("com.example.test.lambda")
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-boot-lambda: Compilation failure
[ERROR] spring-boot-lambda-test-jenkins/lambda-service/spring-boot-lambda/src/main/java/com/example/test/lambda/Application.java:[7,2] cannot find symbol
[ERROR]   symbol: class ComponentScan
它显示已经加载了spring上下文类

+- org.springframework:spring-context:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.3.13.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile
错误:

@ComponentScan("com.example.test.lambda")
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-boot-lambda: Compilation failure
[ERROR] spring-boot-lambda-test-jenkins/lambda-service/spring-boot-lambda/src/main/java/com/example/test/lambda/Application.java:[7,2] cannot find symbol
[ERROR]   symbol: class ComponentScan

这是一个冗余的声明。。。SpringBootApplication还为您提供组件扫描。。。如果您真的想使用@Component,请将@SpringBoot应用程序更改为更小的配置,如@Configuration

但是这样做你会失去Springboot提供的所有自动配置

更新

我已经克隆了您的repo,它构建得很好,除了类配置之外,没有任何其他更改

导入org.springframework.boot.SpringApplication;
导入org.springframework.boot.web.support.SpringBootServletInitializer;
导入org.springframework.context.annotation.ComponentScan;
导入org.springframework.context.annotation.Configuration;
@配置
@组件扫描
公共类应用程序扩展了SpringBootServletInitializer{
公共静态void main(字符串[]args){
SpringApplication.run(Application.class,args);
}
}

代码片段很难说。你进口了吗?我也发现很难得到这个问题。。我实际上从一个开放的repo中签出了代码。它可能无法解析依赖关系,您可以更新应用程序类以查看包和导入吗?您可以共享repo而不是代码片段吗?这样我们就可以自己编译这个项目了。Repo是最简单的版本。不使用组件扫描是的,我知道。。即使我想使用导入。。意思是说找不到符号。。那对我来说很奇怪。。我正在使用RestController注释声明多个文件,但它只占用上下文中的一个控制器。。无法读取任何其他控制器..请查看我对帖子的更新,并考虑到可能您必须提交和推动您的更改,以便我可以评估。。。因为我看到构建错误发生在一个包中,而这个包现在不存在于您的头上。我的本地源代码/src/main/java/com/example/test/lambda/Application.java中没有这个包