- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的主课即使我正在使用应该 Autowiring 所有依赖项的 springbootApplication 注释,我也会收到此错误
@EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"})
@SpringBootApplication(scanBasePackages = {"com.valentine.gram",
"com.valentine.service", "com.valentine"})
@EnableJpaRepositories("com.valentine.dao")
@EnableTransactionManagement
public class MainApp {
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
}
下面是我的堆栈跟踪和 pom 文件,这是一个模块化项目,所以我发布主要的 pom 文件
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-09 23:10:47.131 ERROR 9266 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at com.valentine.gram.MainApp.main(MainApp.java:19) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at
现在pom文件在下面
<dependency>
<groupId>com.valentine.mygram</groupId>
<artifactId>main-app</artifactId>
<version>${project.version}</version>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.version}</version>
</dependency>
<!--servlets-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
</dependency>
关于问题可能是什么以及我如何解决问题的任何建议
最佳答案
据我所知,在 spring boot 中不需要使用像
这样的额外注释@EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"})
@SpringBootApplication(scanBasePackages = {"com.valentine.gram",
"com.valentine.service", "com.valentine"})
@EnableJpaRepositories("com.valentine.dao")
我认为 @SpringBootApplication
足以处理所有这些注释!
而且我不知道你为什么要在 spring boot 中使用所有这些依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.version}</version>
</dependency>
所有这些依赖项都是针对 spring MVC 的,而不是针对 spring boot 的!并且在 spring boot 中无需提及依赖项的版本。喜欢
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
</dependency>
你只能这样写,spring boot会自动处理!
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
关于java - 由于缺少 ServletWebServerFactory bean,即使使用@springbootapplication,我也无法启动 ServletWebServerApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53234386/
我在阻止 Spring Boot 自动配置某些类(在本例中:SolrAutoConfiguration)时遇到了一些困难。为了说明这一点,我设置了一个简化得多的示例: https://github.c
我在阻止 Spring Boot 自动配置某些类时遇到了一些困难(在本例中:SolrAutoConfiguration)。为了说明,我设置了一个大大简化的示例: https://github.com/
根据我的理解,使用@SpringBootApplication相当于拥有@EnableAutoConfiguration和@ComponentScan。由于这个原因,我不明白为什么Spring找不到我
静态文件位于: src/main/resources/static/ js CSS 图片 等.. 无论我做什么,文件都不会被拾取。我试过 addResourceHandlers 但似乎没有任何效果。
我写了一个基于 Spring Boot 的应用程序,但是当我将所有类(模型、用 @restController 注释的 Controller )放在 SpringBoot 存在的同一个包中时,它就可以
我在 nexus 上发布了一个具有包 ID 的公共(public)库 x.xx.common 包含常见Feign客户端代理接口(interface)子包 使用这个库的项目有包 id。 x.xx.acc
我正在努力在简单的 SpringBootApplication 中加载配置。当我尝试打印配置类中的变量时,它们始终为空。 最初,我在 WatchApplication.java 中有可配置变量。然而,
我的 Spring Boot 配置有问题。 我使用 https://start.spring.io/ 创建了基础 Spring Boot 项目 我有一个问题,配置仅适用于子目录中的类: 我尝试过注释@
使用@WebMvcTest 将通过查找@SpringBootConfiguration 类(例如@SpringBootApplication)自动配置所有web 层bean。 如果配置类在不同的包里,
我有一个带有 Autowiring 功能的简单 Spring 应用程序 AppMain,我不想在其中使用任何显式 XML 配置。 在我的 TaskScheduler 组件中,我想将 ThreadPoo
没有@SpringBootApplication,Spring boot应用程序如何工作? 在我们的项目中,我们使用了@Component、@Configuration以及带有@Bean注解的bean
我正在尝试将 spring、非启动应用程序迁移到启动应用程序。当前构建了一个 war 文件。正在关注these说明,我正在逐步完成迁移步骤。 我发现 @SpringBootApplication 注释
我对 SpringBoot 还很陌生。我创建了一个带有服务类的示例应用程序。 下面是我的SpringBootApplication类 @SpringBootApplication public cla
my earlier question 的答案说我应该使用 @SpringBootApplication(scanBasePackages = {"path.to.your.project.root"
我有一个 SpringBootApplication,我想从我的属性文件中读取一个值。 我的@SpringBootApplication类是这样的: @SpringBootApplication @C
如何使用@SpringBootApplication注释从类运行代码。我想运行我的代码而不调用 Controller 并从终端而不是网络浏览器获取信息。我尝试在@SpringBootApplicati
我在 Spring Boot 初始化时遇到了问题。我在一个简单的 Spring Boot 项目中有这个结构。 com.project.name |----App.java (Annoted with
我对 STS 很陌生。我在stackoverflow中搜索了这个错误。我没有找到正确的匹配答案。 我可以在 STS 的 MavenDependencies 部分中看到该类,但无法在我的 java 类中
有没有办法在运行mvn spring-boot:run时指定运行哪个SpringBootApplication的主类? docs说我可以使用 mainClass 参数来指定要运行的主类。但我不确定如何
我试过 @JdbcTest关于以下项目结构。 . ├── pom.xml └── src ├── main │ ├── java │ │ └── com │
我是一名优秀的程序员,十分优秀!