我正在尝试使用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);
}
砰.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
为了简化SpringBoot应用程序中的Pivotal GemFire配置,您可以考虑(从)SpringBootforPivotal-GemFire(SBDG)项目。
SBDG基于Pivotal GemFire (SDG)的Spring数据以及其他Spring项目,特别是Spring Boot,以及Pivotal GemFire(SSDG;这里),也是。在使用Spring开发Pivotal GemFire应用程序时,它应用了Spring Boot的所有概念(例如,固执己见,使用自动配置的“约定优于配置”等),尤其是Spring Boot。
例如,在您的应用程序中,SBDG会自动配置SD[G]存储库,这样就不需要显式声明< code > @ EnableGemfireRepositories 。
使用SBDG还有许多其他好处。
思考的食粮。
您需要将@SpringBootApplication添加到您的主类中。
@EnableGemfireRepositories
@SpringBootApplication
public class Application implements CommandLineRunner {
并在您的pom中添加sping-boot-starter-web依赖项而不是sping-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
我对Spring完全陌生,并开始从这个网站做官方指南:https://spring.io/guides 我想做以下指南:https://spring.io/guides/gs/scheduling-tasks/ 我得到以下异常: 应用程序入门类是这样的: 如您所见,main方法包含一个注释行。我已经做了一个教程,即这个:https://spring.io/guides/gs/consuming-r
我是Spring的新手,所以我从Spring intializr下载了jar for maven-web java 1.8 demo。我将其提取并导入STS以运行main()文件,我得到了以下异常。有人能告诉我有什么解决方案吗? 我从Web尝试但不起作用的解决方案:-尝试将Hibernate验证器依赖项添加到pom-尝试将spring-boot-starter-tomcat依赖项添加到pom 堆栈
运行Spring Boot应用程序时,嵌入式tomcat服务器无法启动。我刚刚在pom.xml中添加了所需的依赖项,并创建了一个简单的java POJO类。应用程序属性已经按照oracle数据库所需的jdbc配置以及Hibernate方言信息进行了设置。 执行mvn spring-boot:run时的控制台日志
我正在学习《行动中的Spring》第四版第5章,但是我被第一个例子困住了。 以下是我的Eclipse Luna项目结构: 如果我将此项目作为Spring Boot应用程序运行,则会引发异常: 我怎样才能解决这个问题? 所有文件的内容: 随地吐痰。爪哇: SpittrWebAppInitializer.java: 网络配置。爪哇: RootConfig。爪哇: HomeController.java
有什么建议吗? 在M.Deinum评论之后更新问题:23-08-2016
我刚开始使用Spring Boot,在运行我的应用程序时出现了错误。我正在学习教程,我相信我有正确的父母和依赖与POM,请帮助我 主类: POM: