把下面的内容翻译成中文如果有html标签和引号或双引号内的内容请不要翻译: Geeting error : Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 出现错误:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。

12 浏览
0 Comments

把下面的内容翻译成中文如果有html标签和引号或双引号内的内容请不要翻译: Geeting error : Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 出现错误:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。

运行Spring Boot应用程序时出错

由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。

我尝试了以下链接中提供的解决方案:

Spring boot -- 由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext

这是我的pom文件

org.springframework.boot

spring-boot-starter-parent

1.5.1.RELEASE

1.8

org.apache.spark

spark-launcher_2.10

2.0.0

org.springframework.boot

spring-boot-starter-data-redis

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-tomcat

javax.servlet

jstl

org.apache.tomcat.embed

tomcat-embed-jasper

provided

org.json

json

javax.servlet

javax.servlet-api

provided

以下是主要部分:

@SpringBootApplication
@ComponentScan("com.howtodoinjava.app")
public class SpringBootWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(SpringBootWebApplication.class);
}
public static void main(String[] args) throws Exception {
    SpringApplication.run(SpringBootWebApplication.class, args);
}
}

以下是控制器:

@Controller
public class IndexController {
private SparkRepo sparkRepo;
public IndexController(SparkRepo sparkRepo) {
    this.sparkRepo = sparkRepo;
}
@RequestMapping(method = RequestMethod.POST, path = "/appLaunch")
public String getData(Model model) throws IOException, InterruptedException {
    int status = sparkRepo.sparkJobStatus();
    model.addAttribute("status", status);
    return "recommendation";
}
// ModelAndView model = new ModelAndView("recommendation");
}

以下是实现:

@Repository
public class SparkImpl implements SparkRepo {
SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
@Override
public int sparkJobStatus() throws IOException, InterruptedException {
    Process spark = new SparkLauncher().setAppResource("/my/app.jar")
            .setMainClass("my.spark.app.Main")
            .setMaster("local")
            .setConf(SparkLauncher.DRIVER_MEMORY, "2g")
            .launch();
    return spark.waitFor();
}
}

运行后出现以下错误:

org.springframework.context.ApplicationContextException:由于缺少EmbeddedServletContainerFactory bean而无法启动嵌入式容器;嵌入式容器应用程序上下文无法启动的嵌套异常。
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at com.howtodoinjava.app.SpringBootWebApplication.main(SpringBootWebApplication.java:19) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: 由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext。
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    ... 8 common frames omitted

我是Spring Boot的新手,尝试了不同的场景,例如添加tomcat的范围,删除它。

但仍然出现错误。

0