Spring Boot 错误:由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

2023-12-07

我正在尝试使用 Spring Data GemFire 将数据放入 GemFire 中。

我跟着这个link

@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 类:

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 添加到您的主类中。

@EnableGemfireRepositories
@SpringBootApplication
public class Application implements CommandLineRunner {

并在您的 pom 中添加 spring-boot-starter-web 依赖项而不是 spring-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Boot 错误:由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext 的相关文章

随机推荐

  • C++ 使用 for 循环反向打印字符串

    我有一个程序 使用 for 循环打印出字符串的字符 它还必须反向打印相同的字符 这就是我遇到问题的地方 有人可以帮我弄清楚为什么第二个 for 循环没有执行吗 int main string myAnimal cout lt lt Plea
  • 将 LineGeometry 与 EllipseGeometry 组合(在代码中,而不是 XAML)

    我正在尝试使用 WPF 创建自定义形状 对于初学者来说 我只是想创建一条简单的线 两端都有一个圆圈 我知道有 LineCaps 但这不是我要找的 我研究了一些教程 最简单的方法似乎是使用CombinedGeometry 但是我无法让它正常工
  • 停止和重置 NSTimer

    我有一个简单的计时器 按下按钮即可激活它 它从 60 运行到 0 没问题 但我想要的是停止并重置按钮上的计时器 我已经设法使用下面的代码在按下按钮时停止它 但由于某种原因无法让它重置并停止在 60 处 这应该很简单 但它不起作用 有什么建议
  • 如何在 WinRT 中的按钮中将文本放置在图像上

    我想创建一个使用图像作为背景的按钮 并在背景之上放置我的文本 我尝试过这样的事情
  • 使用 Django/Python 在创建临时文件的函数之外的内存中打开一个临时文件

    我和这个人度过了最糟糕的时光 在视图中 我创建了一个保存到内存的 csv 文件 我需要将该 csv 文件发送到 utils py 函数并发布到外部 api 我一辈子都不知道该怎么做 这真的让我发疯 我最初只是尝试在下面的 run test
  • python 中 %r、%s 和 %d 有什么区别? [复制]

    这个问题在这里已经有答案了 好吧 我总是在 python 上使用 r 但我不知道什么时候必须使用这些其他格式 这在中进行了解释Python 文档 简而言之 d将格式化一个数字以供显示 s将插入对象的表示字符串 即str o r将插入对象的规
  • 安全的伪流 flv 文件

    We use RTMP通过 Wowza 保护流媒体内容 它就像一个魅力 Wowza 是一个真正强大且健壮的媒体服务器 可用于商业目的 但我们遇到了一个问题 这个问题对我们来说每天都在变得越来越大 许多新客户由于防火墙规则而无法使用RTMP
  • 使用 JavaScript 播放声音

    我想创建一个表格 每行都有字符串和按钮 播放声音 每个按钮播放不同的声音 我想用这个方法来做 这是按钮
  • iPhone 在状态栏中添加图标(如电池指示器)

    我想知道是否可以在 iPhone 状态栏上添加一个图标 就像电池和 WiFi 指示器一样 我怎样才能做到这一点 Thanks 正如之前报道的 使用 SDK 无法做到这一点 如果您在越狱环境中工作 则状态栏图标需要放置在 System Lib
  • 将内联 SVG 保存为 JPEG/PNG/SVG

    我的 html 中有一个内联 SVG 我需要能够将其保存为 JPEG PNG 或 SVG 我尝试了几种不同的方法 将 SVG 转换为画布 然后转换为 JPEG 但我无法使这些方法正常工作 这是我的内联 SVG 的示例 font color
  • 将.CSV转换为.DBF(dBASEIII) VFP 6.0,一切都变成备注字段

    我正在尝试使用 python 将 excel 文件转换为 dbf dBASEIII 我当前的流程是 使用 xlrd 将 excel 文件转换为 csv 我从 csv 中取出标题并使用 获取新制作的 csv并使用dbf模块 https pyp
  • 何时断开与应用程序服务器建立的 bosh 连接以在 strope 中使用预绑定?

    这个问题是我之前关于这个问题的延伸 如何使用java smack库连接XMPP bosh服务器 我使用 Java 作为服务器端语言 我已经使用 smach jbosh 成功实现了 xmpp BOSH 连接 感谢 Deuteu 帮助我实现了这
  • 链接静态库时避免链接未使用的符号

    我正在使用苹果海湾合作委员会编译一个我要重新分发的 dylib 由于各种原因我正在使用一些库 比方说libz为了保持简单 由于这个库通常在 Mac 系统上找不到 我希望静态链接在通过将路径传递给 dylib 使用符号 a file以简化部署
  • C++ 犰狳访问三角矩阵元素

    访问犰狳矩阵的上三角或下三角元素的最有效 即平衡内存和速度 的方法是什么 我知道我可以为元素提供一个整数向量 但随着矩阵变得非常大 我希望避免携带另一个大向量 或者有没有一种有效的方法来快速创建下 上三角指数 例如 5x5 矩阵 C 11
  • 在多个VHost之间共享配置

    我正在管理一个 httpd 安装 其上运行多个站点 每个站点都在其自己的内部定义
  • IE 想要下载 JSON 结果....MVC3

    我的 MVC3 应用程序将用户的文档上传到我们的服务器 我返回一个 JsonResult 以显示任何错误 如果有 HttpPost public JsonResult SaveDocument DocumentModel model Htt
  • 如何使用带有 JSON 数据的 jquery 模板?

    我正在尝试编写一些 jquery 代码来从云帐户检索服务器列表并将它们显示在表格中 当我加载页面时 我的 JavaScript 会执行并返回正确的 JSON 但是当我尝试使用 jquery 模板生成 html 时 我永远不会得到任何输出 谁
  • 使用正则表达式查找页面上而非锚点中的电话号码

    我有这个搜索电话号码模式的正则表达式 d 3 s d 3 s d 4 这会匹配以下格式的电话号码 123 456 7890 123 456 7890 123 456 7890 123 456 7890 123 456 7890 123 45
  • 从数据集和数据表生成水晶报表

    我需要在一个应用程序中的 Crystal Reports 中生成一个报告 其中只有一个独立的数据集 未连接到任何类型的数据库 另外 我需要根据数据表中的值生成报告 能否请您指点一下 我是新手 我有一个模板 但我不知道如何从数据表生成报告 也
  • Spring Boot 错误:由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

    我正在尝试使用 Spring Data GemFire 将数据放入 GemFire 中 我跟着这个link Region stockdata public class StockInfo Id public String symbol pu