Параметр 0 конструктора в com.din.OSS требует bean-компонент типа 'java.lang.String', который не может быть найден - PullRequest
0 голосов
/ 27 июня 2018

Ошибка, которая отображается в консоли после запуска приложения, вставляется ниже

18:46:00.752 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
18:46:00.754 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
18:46:00.754 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/D:/Automation/sts/stsworkspace/BduckApp-1/target/classes/]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m[2m (v2.1.0.BUILD-SNAPSHOT)[0;39m

[2m2018-06-27 18:46:00.946[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.din.BduckApp1Application            [0;39m [2m:[0;39m Starting BduckApp1Application on KOR1064502 with PID 14192 (D:\Automation\sts\stsworkspace\BduckApp-1\target\classes started by rad9kor in D:\Automation\sts\stsworkspace\BduckApp-1)
[2m2018-06-27 18:46:00.947[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.din.BduckApp1Application            [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2018-06-27 18:46:00.991[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@47ebf699: startup date [Wed Jun 27 18:46:00 IST 2018]; root of context hierarchy
[2m2018-06-27 18:46:01.785[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mtrationDelegate$BeanPostProcessorChecker[0;39m [2m:[0;39m Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6d259a6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2m2018-06-27 18:46:02.216[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2018-06-27 18:46:02.229[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.apache.catalina.core.StandardService  [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2018-06-27 18:46:02.229[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet Engine: Apache Tomcat/8.5.31
[2m2018-06-27 18:46:02.233[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.a.catalina.core.AprLifecycleListener  [0;39m [2m:[0;39m The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre8/bin/server;C:/Program Files/Java/jre8/bin;C:/Program Files/Java/jre8/lib/amd64;C:\Perl520\Perl64\bin;C:\Perl520\Perl64\site\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\7-Zip;C:\Program Files\TortoiseSVN\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files\7-Zip;C:\Program Files\Black Duck Software\protexIP\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\Black Duck Software\protexIP\bin;C:\Program Files\7-Zip;C:\Program Files (x86)\Toolbase Client;C:\Program Files\Git\cmd;C:\Users\rad9kor\anaconda3;C:\Users\rad9kor\anaconda3\Library\mingw-w64\bin;C:\Users\rad9kor\anaconda3\Library\usr\bin;C:\Users\rad9kor\anaconda3\Library\bin;C:\Users\rad9kor\anaconda3\Scripts;D:\Automation\sts\tool\sts-bundle\sts-3.9.4.RELEASE;;.]
[2m2018-06-27 18:46:02.329[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2018-06-27 18:46:02.329[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.web.context.ContextLoader           [0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1340 ms
[2m2018-06-27 18:46:02.459[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.ServletRegistrationBean [0;39m [2m:[0;39m Servlet dispatcherServlet mapped to [/]
[2m2018-06-27 18:46:02.460[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.ServletRegistrationBean [0;39m [2m:[0;39m Servlet webServlet mapped to [/h2-console/*]
[2m2018-06-27 18:46:02.462[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean  [0;39m [2m:[0;39m Mapping filter: 'characterEncodingFilter' to: [/*]
[2m2018-06-27 18:46:02.463[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean  [0;39m [2m:[0;39m Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
[2m2018-06-27 18:46:02.463[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean  [0;39m [2m:[0;39m Mapping filter: 'httpPutFormContentFilter' to: [/*]
[2m2018-06-27 18:46:02.463[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[ost-startStop-1][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean  [0;39m [2m:[0;39m Mapping filter: 'requestContextFilter' to: [/*]
[2m2018-06-27 18:46:02.570[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Starting...
[2m2018-06-27 18:46:02.628[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Start completed.
[2m2018-06-27 18:46:02.660[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Building JPA container EntityManagerFactory for persistence unit 'default'
[2m2018-06-27 18:46:02.669[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
[2m2018-06-27 18:46:02.816[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.hibernate.Version                   [0;39m [2m:[0;39m HHH000412: Hibernate Core {5.3.1.Final}
[2m2018-06-27 18:46:02.817[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.hibernate.cfg.Environment           [0;39m [2m:[0;39m HHH000206: hibernate.properties not found
[2m2018-06-27 18:46:02.869[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.hibernate.annotations.common.Version  [0;39m [2m:[0;39m HCANN000001: Hibernate Commons Annotations {5.0.3.Final}
[2m2018-06-27 18:46:02.954[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.hibernate.dialect.Dialect           [0;39m [2m:[0;39m HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
[2m2018-06-27 18:46:03.084[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.h.t.schema.internal.SchemaCreatorImpl [0;39m [2m:[0;39m HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@152501c5'
[2m2018-06-27 18:46:03.086[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default'
[2m2018-06-27 18:46:03.099[0;39m [33m WARN[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bduckTrigger': Unsatisfied dependency expressed through field 'oss'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OSS' defined in file [D:\Automation\sts\stsworkspace\BduckApp-1\target\classes\com\din\OSS.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
[2m2018-06-27 18:46:03.099[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Closing JPA EntityManagerFactory for persistence unit 'default'
[2m2018-06-27 18:46:03.099[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36m.SchemaDropperImpl$DelayedDropActionImpl[0;39m [2m:[0;39m HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
[2m2018-06-27 18:46:03.101[0;39m [33m WARN[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.f.support.DisposableBeanAdapter   [0;39m [2m:[0;39m Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]
[2m2018-06-27 18:46:03.101[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Shutdown initiated...
[2m2018-06-27 18:46:03.103[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Shutdown completed.
[2m2018-06-27 18:46:03.105[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.apache.catalina.core.StandardService  [0;39m [2m:[0;39m Stopping service [Tomcat]
[2m2018-06-27 18:46:03.114[0;39m [32m INFO[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mConditionEvaluationReportLoggingListener[0;39m [2m:[0;39m 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2018-06-27 18:46:03.208[0;39m [31mERROR[0;39m [35m14192[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.d.LoggingFailureAnalysisReporter  [0;39m [2m:[0;39m 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.din.OSS required a bean of type 'java.lang.String' that could not be found.


Action:

Consider defining a bean of type 'java.lang.String' in your configuration.

В пакете 3 класса

com.din

BduckApp1Application.java <- Приложение SpringBoot </p>

BduckTrigger.java <- RestController </p>

OSS.java <-Data class </p>

BduckApp1Application .java

package com.din;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
  public class BduckApp1Application {

public static void main(String[] args) {
    SpringApplication.run(BduckApp1Application.class, args);
}
}

BduckTrigger.java

package com.din;

import java.util.Vector;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BduckTrigger {
@Autowired
OSS oss;

Vector<OSS> osses = new Vector<>();
@RequestMapping("/bd")
public Vector<OSS> LogintoProtex() {
    oss = OSS.builder().name("Dinesh").version("1.0").license("apache 2.0").usage("dynamic").comment("approved").build();
    osses.add(oss);
    oss = OSS.builder().name("Nikesh").version("2.0").license("BSD 2.0").usage("static").comment("disapproved").build();
    osses.add(oss);
    return osses;

}

}

OSS.java

package com.din;

import org.springframework.stereotype.Component;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@Component
public class OSS {
 public String name;
 public String version;
 public String license;
 public String usage;
 public String comment;
}

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.din.bd</groupId>
    <artifactId>BduckApp-1</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>BduckApp-1</name>
    <description>Microservice project for Bduck</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</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>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

Я перепробовал все решения, которые упоминаются для аналогичной ошибки в различных сообщениях stackoverflow. Все предлагает переместить классы в ту же папку, что и класс @SpringBootApplication, или включить пакет с атрибутом basepackage. Никто не работал для меня. Любая помощь будет отличной!

1 Ответ

0 голосов
/ 27 июня 2018

Осторожно: вы настроили свой компонент OSS для Spring и Lombok.
А про Lombok вы объявили на уровне класса @Builder, что, вероятно, имеет следствие для генерации конструктора.

И проблема в том, что в Spring 4 по умолчанию компонент Spring, который объявляет конструктор, автоматически рассматривается как конструктор с автопроводкой.
В то время как исключение вы встречаете.

Видя, как вы создали экземпляр экземпляра OSS:

oss = OSS.builder().name("Dinesh").version("1.0").license("apache 2.0").usage("dynamic").comment("approved").build();

OSS не обязательно должен быть сконфигурирован bean-компонент Spring, но должен быть простым объектом, созданным под рукой.
Вы не хотите создавать отдельный экземпляр этого объекта, вы хотите создать его экземпляр в соответствии с запросом клиента и, наконец, вы не хотите делить его между клиентами.
Так что просто удалите аннотацию @Component этого класса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...