简体   繁体   中英

spring boot compilation cannot find symbol componentscan

i am getting connot find symbol component scan error in my small spring boot project. any idea where i am going wrong.

base class:

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

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

config class

@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;
            }
        };
    }

}

dependency tree:

it shows spring context classes are already loaded..

+- 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

error:

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

This is a redundant declararion... SpringBootApplication also provides you a componentScan... if you really want to use @ComponentScan change your @SpringBootApplication for something smaller like a @Configuration....

But doing that you gonna loose all the auto-configuration provided by Springboot.

Springboot configuration annotation explanation

Update

I've cloned your repo and it build well, without any fuhter changing anything but your class configuration

Maven build succesfully

import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM