当前位置: 首页 > 知识库问答 >
问题:

com.din.oss中构造函数的参数0需要一个类型为“java.lang.String”的bean,但找不到

百里涛
2023-03-14

运行应用程序后控制台显示的错误粘贴在下面

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个等级

bduckapp1application.java<-SpringBoot应用程序

bducktrigger.java<-restcontrol

oss.java<-data类

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);
}
}
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;

}
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个答案

柳业
2023-03-14

注意:您为Spring和Lombok配置了OSSbean.
,关于Lombok,您在类级别声明了@builder,这可能会生成一个构造函数。

问题是,从Spring4开始,默认情况下,声明构造函数的Spring组件会自动被视为autowired构造函数。

看到您实例化OSS实例的方式:

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

OSS不必配置为Spring bean,但必须是手边创建的普通对象。
您不想创建这个对象的单个实例,您希望根据客户机请求实例化它,最后您也不希望在客户机之间共享它。
所以只需删除该类的@component注释。

 类似资料:
  • 我正在创建一个,其中任何客户端都可以提交请求,这些请求可以是、、、。 但是在创建这个应用程序时,我遇到了以下错误: 我的应用程序的结构是: 我尝试用、、注释,但仍然得到相同的错误。 我甚至从这些答案中尝试了解决方案: (1)构造函数的参数0需要一个类型为'java.lang.String'的bean,但找不到该bean 但我仍然无法解决我的问题。

  • 我正在用spring Boot2.x应用程序处理spring batch,实际上它的现有代码我是从Git签出的。在运行应用程序时,它失败了,因为下面的错误只对我来说,同样的代码是为其他人工作的。 我已经检查了下面 null

  • 我想有一个SSO CAS认证,我已经按照Bealdung的教程(https://www.baeldung.com/spring-security-cas-sso第4部分)的说明,但当我作为Spring启动应用程序运行时,我有这个错误 SecurityConfig中构造函数的参数0需要找不到类型为“org.springframework.security.cas.authentication.Cas

  • 在此处输入图像描述 在此处输入图像描述 我仍然不知道该怎么办(我在UserRepository上尝试了Repository注释-错误是一样的)。错误消息:`启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2022-03-14 09:04:54.626错误7236---[main]o.s.b.d.LoggingFailureAnalysisR

  • 我不确定我的代码有什么问题。我试着学习Spring Boot WebFlux。但我无法运行应用程序,因为我得到以下错误: com.thomsoncodes.todo.controller.ToDoController中构造函数的参数0需要一个类型为“com.thomsoncodes.todo.repository.ToDoRespository”的bean,但找不到该bean 疲惫@Autowir