3

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
Reese
  • 389
  • 2
  • 10
  • 26

1 Answers1

0

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);
    }
}
  • yeah that i know.. even if i want to use import.. it is saying cannot find symbol.. that is strange to me.. i am declaring multiple files with RestController annotation but it is only taking up one controller in the context.. cannot read any other controller.. – Reese Sep 02 '20 at 12:01
  • Please see the update I made to my post with the considerations – Karllos Ernnesto Sep 02 '20 at 13:59
  • Maybe you have to commit and push your changes so i can evaluate... Because i saw that the build error is being made in a package that does not exist now on your HEAD. I dont have this package on my local source of your code _/src/main/java/com/example/test/lambda/Application.java_ – Karllos Ernnesto Sep 02 '20 at 14:06