这是我的application.yml文件:server: port: 8089schedulers: identity: origin: http://localhost:7189 client-id: 72612d8e-b78e-446c-9397-354435696ec3 secret: 173a7f6a-8263-11e7-bb31-be2e44b06b34 username: integrationCLient password: P@ssword token-cache-backoff: 5 default-token-cache-ttl: 5 endpoints: validateToken: /v3/api/validateToken issueToken: /v3/api/oauth/v2/token httpClient: numOfRetries: 3 backOffInMillis: 5 couchbase: bootstrapHost: localhost bucket: default connectionTimeout: 1000我正在尝试将该文件读入我的 Spring Boot 应用程序。这是相关的代码:@Configuration@ConfigurationProperties(prefix = "schedulers")@Getter@Setterpublic class CouchbaseConfig { CouchbaseContext couchbaseContext = new CouchbaseContext(); @Bean public Bucket bucket() { System.out.println("askfjaslkfjafa" + couchbaseContext.getBootstrapHost()); //throws NPE CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder() .connectTimeout(Long.parseLong(couchbaseContext.getConnectionTimeout())) .build(); Cluster cluster = CouchbaseCluster.create(env, couchbaseContext.getBootstrapHost()); return cluster.openBucket(couchbaseContext.getBucket()); }}这是我的CouchbaseContext.java文件:进口 lombok.Getter; 进口 lombok.Setter;@Getter@Setterpublic class CouchbaseContext { private String bootstrapHost; private String bucket; private String connectionTimeout;}我正在NPE试图访问couchbaseContext的对象CouchbaseConfig.java。有人可以帮助我解决我做错了什么吗?
1 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
@EnableConfigurationProperties({
CouchbaseContext.class
})
@Configuration
public class CouchbaseConfig {
@Bean
public Bucket bucket(CouchbaseContext couchbaseContext) { ... }
}
此外,您可以删除 CouchbaseContext 中的 @Configuration
添加回答
举报
0/150
提交
取消