springboot启动报错Parameter 0 of method a in com.* required a bean of type 'java.lang.String' that could

本文解析了SpringBoot服务启动时出现的特定错误,详细分析了由于@Autowired注解引起的异常情况,提供了有效的解决策略,包括如何正确配置依赖注入以及使用@Bean注解手动创建实例的方法。

springboot服务启动报错,报错信息如下

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

Description:

Parameter 0 of method testServicein com.test.service.testService 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.

本地代码如下

package com.test.service;
@Service("test")
public class Test{
	@Autowired
	private DeviceService deviceService;
	...
	@Autowired
	@Async("asyncTestExecutor")
	public void testService(String message){
	...
	}
}

公司项目kafka服务启动报错,报错信息如上。
说报错信息是由于A类中定义了含参数的构造函数,Spring自动构造和注入时未为该Bean传入参数,引起报错。
最后是因为注释的时候没有把@Autowired一同注释掉,有一个空的@Autowired引起报错,导致项目启动报错。

若不是像我这样出现问题的,可以有其他解决办法,比如:
解决方案:使用@Bean注解手动创建ImageServiceImpl的实例,具体步骤如下:
1、定义BeanConfig类(或者将Bean的定义直接写在Application启动类中)
2、修改ImageServiceImpl(含有参构造函数的Bean)。
具体的可以查询其他

ERROR 12760 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'com.forest.support.auth.server.config.SecurityConfig': Unsatisfied dependency expressed through method 'setAuthServer' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.forest.support.auth.server.service.AuthServer<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 2025-09-15 15:20:23.841 INFO 12760 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2025-09-15 15:20:23.845 WARN 12760 --- [ main] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [Druid-ConnectionPool-Create-700262294] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2813) 2025-09-15 15:20:23.846 WARN 12760 --- [ main] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [Druid-ConnectionPool-Destroy-700262294] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method) com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2913) 2025-09-15 15:20:23.848 WARN 12760 --- [ main] 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 2025-09-15 15:20:23.849 INFO 12760 --- [ main] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource start closing .... 2025-09-15 15:20:23.851 INFO 12760 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closing ... 2025-09-15 15:20:23.854 INFO 12760 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed 2025-09-15 15:20:23.854 INFO 12760 --- [ main] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource all closed success,bye 2025-09-15 15:20:23.874 INFO 12760 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-09-15 15:20:23.928 ERROR 12760 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of method setAuthServer in com.forest.support.auth.server.config.SecurityConfig required a bean of type 'com.forest.support.auth.server.service.AuthServer' that could not be found. Action: Consider defining a bean of type 'com.forest.support.auth.server.service.AuthServer' in your configuration.
09-16
评论 25
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值