@使用IntelliJ而不是Eclipse的Spring引导应用程序中的组件扫描错误
我正在开发一个Spring Boot-应用程序,它使用Maven进行构建管理。我已将此应用程序导入IntelliJ IDEA Ultimate 16.1。如果运行我的主类,我会出现以下错误: 此方法的代码(包括上述消息中的error point Application.java第43行)为: 显示的这行代码没有quicktip或错误@使用IntelliJ而不是Eclipse的Spring引导应用程序中的组件扫描错误,spring,intellij-idea,spring-boot,spring-annotations,Spring,Intellij Idea,Spring Boot,Spring Annotations,我正在开发一个Spring Boot-应用程序,它使用Maven进行构建管理。我已将此应用程序导入IntelliJ IDEA Ultimate 16.1。如果运行我的主类,我会出现以下错误: 此方法的代码(包括上述消息中的error point Application.java第43行)为: 显示的这行代码没有quicktip或错误 如果我将它导入到eclipseneo中,它运行时不会出现任何错误,我可以访问我的web应用程序。如果我运行Maven install(例如,在IntelliJ之外)
如果我将它导入到eclipseneo中,它运行时不会出现任何错误,我可以访问我的web应用程序。如果我运行Maven install(例如,在IntelliJ之外),那么也会为一些测试用例启动应用程序。因此,错误似乎是由IntelliJ的设置引起的。在“项目结构”菜单中,没有显示任何问题,Spring应用程序上下文充满了应用程序(没有显示“无上下文类”)。您可能缺少此依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
org.springframework.boot
SpringBootStarterWeb
您可以尝试以下方法:
选择:文件->项目结构->模块->依赖项
查找:tomcat嵌入核心(提供了这个jar包默认值,更改为编译)我也遇到了同样的问题(应用程序在eclipse中运行,而不是在intellij中运行)
在我的pom.xml中,tomcat嵌入jasper和javax.servlet提供了作用域
我注释掉了这些范围,现在一切正常。也许你的问题与罐子的放置位置有关,intellij可能会在其他地方找到它们。您是否将您的
应用程序类放在默认包中?@LipingHuang它放在一个完整命名的包中,例如com.my.Application.Application.java此依赖项已添加。如果缺少,Eclipse也无法启动。在Maven项目工具栏上单击“重新导入所有Maven项目”,它没有改变任何内容。项目的完全重新导入也没有改变什么。这似乎是一个设置错误。
@EnableAutoConfiguration
@ComponentScan("com.applicationpackage")
@SpringBootApplication
@EnableScheduling
public class Application extends WebMvcConfigurerAdapter {
private static ConfigurableApplicationContext context;
@Autowired
private ServletContext servletContext;
public static void main(String[] args) throws Exception {
Application.context = SpringApplication.run(Application.class, args);
Application.context.registerShutdownHook();
}
...
}
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>