【发布时间】:2016-03-16 18:17:33
【问题描述】:
我是 spring-boot 和 couchbase 的新手。我写了一个简单的应用程序,我试图连接到我的 couchbase 存储桶,但是在启动时它会抛出错误。
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$$EnhancerBySpringCGLIB$$6f4ff8c5]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$$EnhancerBySpringCGLIB$$6f4ff8c5.<init>()
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:773) [spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:368) [spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1190) [spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1179) [spring-boot-1.4.0.BUILD-SNAPSHOT.jar:1.4.0.BUILD-SNAPSHOT]
我的班级是这样的
@Configuration
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class ShippingFeesApplication {
@Autowired
public CouchBaseBasicRepository<ShippingFeesParams> repo;
@Autowired
public CouchBaseConfiguration config;
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(ShippingFeesApplication.class, args);
ctx.close();
}
@Bean
CommandLineRunner commandLineRunner(){
return args -> { ShippingFeesParams singleObject = new ShippingFeesParams();
String key = "GUS/ANDROID/10001";
singleObject.setId(key);
singleObject.setAddOnThreshold(25.00);
singleObject.setCreatedDate(Calendar.getInstance().getTime());
singleObject.setDeliveryType(1);
singleObject.setFreeShippingThreshold(49.99);
singleObject.setLastModifiedDate(Calendar.getInstance().getTime());
AdditionShippingRules rules = new AdditionShippingRules();
rules.setBaseShippingPrice(9.95);
rules.setHeavyWeightShippingPrice(14.99);
rules.setStoreId("10001");
singleObject.setAdditionRules(rules);
repo.save(singleObject);
repo.findOne(key);
Iterable<ShippingFeesParams> shippingFees = repo.findAll();
shippingFees.forEach((shipping)-> log.info(shipping.toString()));
};
}
}
CouchbaseBasicRepository
@Component
public interface CouchBaseBasicRepository<BaseDataType extends CouchBaseDocument> extends CrudRepository<BaseDataType, String> {
}
沙发底座配置
@Configuration
@EnableAutoConfiguration
@EnableCouchbaseRepositories
public class CouchBaseConfiguration extends AbstractCouchbaseConfiguration {
@Value("${couchbase.bucket.name:shiping_fees_config}")
private String bucketName;
@Value("${couchbase.bucket.password}")
private String password;
@Value("${couchbase.bootstrap-hosts:127.0.0.1}")
private String ip;
@Override
protected List<String> bootstrapHosts() {
return Arrays.asList(ip);
}
@Override
public String getBucketName() {
return bucketName;
}
@Override
protected String getBucketPassword() {
return password;
}
}
这是我的 pom 文件
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>
<dependency>
<groupId>com.staples.gp</groupId>
<artifactId>domain-shipping</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.staples.gp</groupId>
<artifactId>api-common</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler</artifactId>
<version>2.7.8</version>
</dependency>
</dependencies>
【问题讨论】:
-
这个错误是关于嵌入式tomcat的,所以它至少不太可能与couchbase集成有关
-
您确定 couchbase 正在运行并且可以访问吗?
-
是的,沙发底座可以使用。
标签: tomcat spring-boot java-8 couchbase