복붙노트

[SPRING] 스프링 부트 오류 : EmbeddedServletContainerFactory 빈이 없어서 EmbeddedWebApplicationContext를 시작할 수 없습니다.

SPRING

스프링 부트 오류 : EmbeddedServletContainerFactory 빈이 없어서 EmbeddedWebApplicationContext를 시작할 수 없습니다.

Spring Data GemFire를 사용하여 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 클래스 :

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.hml :

    <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

해결법

  1. ==============================

    1.@SpringBootApplication을 기본 클래스에 추가해야합니다.

    @SpringBootApplication을 기본 클래스에 추가해야합니다.

    @EnableGemfireRepositories
    @SpringBootApplication
    public class Application implements CommandLineRunner {
    

    당신의 pom에 spring-web 대신 spring-boot-startter-web 의존성을 추가하십시오

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

    2.Spring Boot 응용 프로그램에서 Pivotal GemFire ​​구성을 단순화하기 위해 SBDG (Pivotal GemFire) 용 Spring Boot 프로젝트를 사용하는 것이 좋습니다.

    Spring Boot 응용 프로그램에서 Pivotal GemFire ​​구성을 단순화하기 위해 SBDG (Pivotal GemFire) 용 Spring Boot 프로젝트를 사용하는 것이 좋습니다.

    SBDG는 다른 Spring 프로젝트, 분명히 Spring Boot뿐만 아니라 Pivotal GemFire ​​(SSDG) 용 Spring Session과 함께 Pivotal GemFire ​​(SDG) 용 Spring Data를 기반으로합니다. Pivotal GemFire ​​응용 프로그램을 일반적으로 Spring 및 Spring Boot와 함께 개발할 때 Spring Boot의 모든 개념 (예 : 독창적 인 구성, 자동 구성을 사용하는 구성 등)을 적용합니다.

    예를 들어, 애플리케이션에서 SBDG는 자동으로 SD [G] 저장소를 자동 구성하므로 @EnableGemfireRepositories의 명시 적 선언은 필요하지 않습니다.

    SBDG를 사용하면 많은 다른 이점도 있습니다.

    생각할 거리.

  3. from https://stackoverflow.com/questions/34022580/spring-boot-error-unable-to-start-embeddedwebapplicationcontext-due-to-missing by cc-by-sa and MIT license