![](/img/trans.png)
[英]cannot find symbol import com.google.firebase.iid.FirebaseInstanceId;
[英]spring boot compilation cannot find symbol componentscan
我在我的小型 spring 引導項目中遇到無法找到符號組件掃描錯誤。 知道我哪里出錯了。
基地 class:
@ComponentScan("com.example.test.lambda")
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
配置 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;
}
};
}
}
依賴樹:
它顯示 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
錯誤:
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 還為您提供了一個 componentScan ...
但是這樣做你會失去 Springboot 提供的所有自動配置。
更新
我已經克隆了你的 repo 並且它構建得很好,除了你的 class 配置之外沒有任何改變
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.