Spring Boot错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext [英] Spring Boot error: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

查看:120
本文介绍了Spring Boot错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用Spring Data GemFire将数据放入GemFire.

I am trying to put the data into GemFire by using Spring Data GemFire.

我遵循了这个链接

@Region("stockdata")
public class StockInfo {

    @Id 
    public String symbol;

    public String price;

    @PersistenceConstructor
    public StockInfo(String symbol, String price) {
        super();
        this.symbol = symbol;
        this.price = price;
    }

    @Override
    public String toString() {
        return "StockInfo [symbol=" + symbol + ", price=" + price + "]";
    }

    public String getSymbol() {
        return symbol;
    }
    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }

}

StockRepository类:

StockRepository class:

public interface StockRepository extends CrudRepository<StockInfo, String> {
    StockInfo findByName(String symbol);

}

主类:

@Configuration
@EnableGemfireRepositories
public class Application implements CommandLineRunner {

    @Bean
    CacheFactoryBean cacheFactoryBean() {
        return new CacheFactoryBean();

    }

    @Bean
    LocalRegionFactoryBean<String, StockInfo> localRegionFactory(final GemFireCache cache) {
        return new LocalRegionFactoryBean<String, StockInfo>() {

            {
                setCache(cache);
                setName("stockdata");
                setClose(false);
            }
        };
    }
    @Autowired
    StockRepository stockRepositry;
    public void run(String... arg0) throws Exception {
        StockInfo fbStock = new StockInfo("FB", "100");
        StockInfo aaplStock = new StockInfo("AAPL", "200");
        StockInfo msftStock = new StockInfo("MSFT", "300");

        System.out.println("Before linking up with Gemfire...");
        for (StockInfo stockInfo : new StockInfo[] {fbStock, aaplStock,msftStock }) {
            System.out.println("\t" + stockInfo);
        }

        stockRepositry.save(fbStock);
        stockRepositry.save(aaplStock);
        stockRepositry.save(msftStock);

        System.out.println("Lookup each Stock by name...");

        for (String symbol : new String[] { fbStock.symbol, aaplStock.symbol,msftStock.symbol }) {
            System.out.println("\t" + stockRepositry.findByName(symbol));
        }

    }

    public static void main(String[] args) throws IOException {
        SpringApplication.run(Application.class, args);
    }

Pom.xml:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.7</java.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-gemfire</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency> 
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
    </dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories> 

错误如下:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at com.emc.geode.entity.Application.main(Application.java:62) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:183) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:156) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    ... 8 common frames omitted

推荐答案

您需要在主类中添加@SpringBootApplication.

You need to add @SpringBootApplication to your main class.

@EnableGemfireRepositories
@SpringBootApplication
public class Application implements CommandLineRunner {

然后在pom中添加spring-boot-starter-web依赖关系,而不是spring-web

and in your pom add spring-boot-starter-web dependency instead of spring-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

这篇关于Spring Boot错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆