首页 > 解决方案 > 启动 Spring Boot 服务器/创建连接到我的 CouchBaseConfig 的自动装配 bean 的问题

问题描述

所以我试图重新创建一个我在我的另一台本地机器上制作的项目。现在该项目运行良好,但是一旦我开始将其配置到新机器上,它就会刹车。我假设的问题在于 Config 类和 autobeaning(StackTrace)。当谈到 Spring/autobeaning 时,我并不是很了解,因此尽管我无法弄清楚,但它可能是显而易见的。

我尝试添加不同的依赖项并确保我的注释是正确的,但问题仍然存在 application.yml

spring:
  profiles: development
  couchbase:
    bootstrap-hosts: http://localhost:8080
    bucket:
      name: test
      password: qwerty

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bhagyesh</groupId>
    <artifactId>NYC146WithSpring</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-couchbase</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-jms-client</artifactId>
            <version>0.44.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-pool</artifactId>
            <version>5.15.9</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.1.4</version>
        </dependency>
        <!-- Testing -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin.external.google</groupId>
            <artifactId>android-json</artifactId>
            <version>0.0.20131108.vaadin1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
        </dependency>

        <dependency>
            <groupId>com.smartystreets.api</groupId>
            <artifactId>smartystreets-java-sdk</artifactId>
            <version>3.3.8</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>  <!--or <release>10</release>-->
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

配置类:

package com.dogboy60.NYC146.manager;

SOME MORE IMPORT

import java.util.List;

@Configuration
@EnableConfigurationProperties({CouchbaseProperties.class})

public class CouchBaseConfig extends AbstractCouchbaseConfiguration {

    @Autowired
    private CouchbaseProperties couchbaseProperties;

    @Override
    protected List<String> getBootstrapHosts() {
        return couchbaseProperties.getBootstrapHosts();
    }

    @Override
    protected String getBucketName() {
        return couchbaseProperties.getBucket().getName();
    }

    @Override
    protected String getBucketPassword() {
        return couchbaseProperties.getBucket().getPassword();
    }

    @Override
    protected CouchbaseEnvironment getEnvironment(){
        return DefaultCouchbaseEnvironment.create();
    }
}

EventModelRepoImpl 类:

package com.dogboy60.NYC146.data.repo;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.dogboy60.NYC146.data.model.EventDocument;
import com.dogboy60.NYC146.manager.JsonToObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Collection;

public class EventModelRepoImpl implements EventModelCustomRepo {
    @Autowired
    private JsonToObject JTO;
    @Autowired
    private EventModelRepo eventModelRepo;
    @Autowired
    private Bucket bucket;

    /**
     * Events is updated, the ID is automatically calculated.
     * @param eventDocument the document that you want to update (this is the new Version)
     */
    @Override
    public void updateEvent(EventDocument eventDocument) {
        ...
    }

    /**
     * Events is updated, the ID is passes in via the POJO.
     * @param eventDocument
     */
    @Override
    public void removeEvent(EventDocument eventDocument) {
        ...
    }

    /**
     * ID Generated and set to POJO
     * If it exists then Error occurs
     * @param eventDocument the document that is to be added
     */
    @Override
    public void addPost(EventDocument eventDocument) {
        ....
    }

    /**
     *
     * @param Season which season is wanted
     * @param Price what price point is wanted
     * @return returns a post that matches the price and season (collection) though can be empty
     */
    @Override
    public Collection<EventDocument> getPost(String Season, String Price) {
        ...
    }

    /**
     *
     * @param id ID of the document we are looking for
     * @return true or false based on if the Doc with given ID exists
     */
    @Override
    public boolean contains(String id) {
            ...

    }
    /**
     *
     * @param eventDocument eventDocument has its ID taken and then looks for it
     * @return true or false based on if the Doc with given eventDocument exists
     */
    @Override
    public boolean contains(EventDocument eventDocument) {
        ...
    }

    /**
     * If Doc exist it will return ot else it will throw an error
     * @param ID The ID of the Doc we are looking for
     * @return the document that we just requested
     */
    @Override
    public EventDocument getPost(String ID) {
        ...
    }



    /**
     * format: Name_( Address.noSpace() )
     * @param name Name of event
     * @param address Address of the Event
     * @return THe ID generated with given Info
     */
    public String IDgenerator(String name,String address){
      ..
    }

}

尽管出现自动 bean 错误,但要启动本地服务器:

2019-07-06 18:35:13.391  INFO 5212 --- [  restartedMain] com.dogboy60.NYC146.App                  : Starting App on DESKTOP-T5Q9S3P with PID 5212 (C:\Users\JARVIS-MAIN\Documents\Nyc\NYC146\target\classes started by JARVIS-MAIN in C:\Users\JARVIS-MAIN\Documents\Nyc\NYC146)
2019-07-06 18:35:13.393  INFO 5212 --- [  restartedMain] com.dogboy60.NYC146.App                  : No active profile set, falling back to default profiles: default
2019-07-06 18:35:13.424  INFO 5212 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-07-06 18:35:13.425  INFO 5212 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-07-06 18:35:14.320  INFO 5212 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-07-06 18:35:14.381  INFO 5212 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 56ms. Found 1 repository interfaces.
2019-07-06 18:35:14.655  INFO 5212 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-07-06 18:35:14.662  INFO 5212 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 0 repository interfaces.
2019-07-06 18:35:14.922  INFO 5212 --- [  restartedMain] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2019-07-06 18:35:14.927  INFO 5212 --- [  restartedMain] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2019-07-06 18:35:14.932  INFO 5212 --- [  restartedMain] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2019-07-06 18:35:15.015  INFO 5212 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration$$EnhancerBySpringCGLIB$$bea0f4bf] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-06 18:35:15.022  INFO 5212 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-06 18:35:15.308  INFO 5212 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-07-06 18:35:15.333  INFO 5212 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-07-06 18:35:15.333  INFO 5212 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-07-06 18:35:15.426  INFO 5212 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-07-06 18:35:15.426  INFO 5212 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2001 ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/JARVIS-MAIN/.m2/repository/org/springframework/spring-core/5.1.8.RELEASE/spring-core-5.1.8.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-07-06 18:35:15.680 ERROR 5212 --- [  restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseCluster' defined in class path resource [com/dogboy60/NYC146/manager/CouchBaseConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Cluster]: Factory method 'couchbaseCluster' threw exception; nested exception is java.lang.NullPointerException
2019-07-06 18:35:15.692  INFO 5212 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-07-06 18:35:15.696  WARN 5212 --- [  restartedMain] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [cb-tracing-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
MORE ERROR CODE...
2019-07-06 18:35:15.700  WARN 5212 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
MORE ERROR CODE...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseCluster' defined in class path resource [com/dogboy60/NYC146/manager/CouchBaseConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Cluster]: Factory method 'couchbaseCluster' threw exception; nested exception is java.lang.NullPointerException

MORE ERROR CODE...
Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration
MORE ERROR CODE...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseCluster' defined in class path resource [com/dogboy60/NYC146/manager/CouchBaseConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Cluster]: Factory method 'couchbaseCluster' threw exception; nested exception is java.lang.NullPointerException
SOME MORE ERROR....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseCluster' defined in class path resource [com/dogboy60/NYC146/manager/CouchBaseConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Cluster]: Factory method 'couchbaseCluster' threw exception; nested exception is java.lang.NullPointerException


标签: javaspringspring-bootautowired

解决方案


推荐阅读