gpt4 book ai didi

tomcat - 使用 couchbase 启动 spring boot 应用程序时出错 Error creating bean with name 'tomcatEmbeddedServletContainerFactory'

转载 作者:行者123 更新时间:2023-11-28 23:26:47 24 4
gpt4 key购买 nike

我是 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]

我的类(class)是这样的

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

最佳答案

尝试删除应用类中的冗余注释。

@Configuration
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan

可以简化为

@SpringBootApplication

这个注解是一个包含其他注解的元注解。

关于tomcat - 使用 couchbase 启动 spring boot 应用程序时出错 Error creating bean with name 'tomcatEmbeddedServletContainerFactory',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com