Error content:
when using the automatic injection of springboot, the configuration file in yaml format is used for injection, but the error is always reported and cannot be injected.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘helloController’: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘name’ in value “${name}”
I searched many posts saying that I should pay attention to the application scanning my folder and corresponding subfolders. Many people step on the pit in this place, but my problem is not here
code
@RestController
public class HelloController {
@Value(value = "${name}")
private String name;
@RequestMapping("/hello")
public String hello(){
System.out.println(name);
return "hello Spring Boot !";
}
}
Add the annotation to read the configuration file on hellocontroller
@PropertySource(value = "classpath:application.yaml")
That solved the problem
Read More:
- @Autowired injection * * required a single bean, but 2 were found**
- Datasource bean injection failed, with startup error
- Error creating bean with name ‘application‘: Instantiation of bean failed;
- Error creating bean with name xxxxxx : unsatisfied dependency…
- Error creating bean with name ‘xxcontroller’
- Error creating bean with name ‘datasource’ defined in class path resource
- An error is reported when springboot starts: error creating bean with name ‘XXXX’
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
- Error creating bean with name ‘redisTemplate‘ defined in class path resource [xx/RedisConfig.class]
- Error creating bean with name ‘enablererediskeyspacenotificationsinitializer’
- Error creating bean with name usercontroller appears when springboot starts
- Error creating bean with name ‘redissonclient’:
- Error creating bean with name ‘requestMappingHandlerAdapter‘ defined in class path resource
- elasticsearch NoClassDefFoundError error creating RestHighLevelClient bean
- Solution to the problem of spring boot running test class error creating bean with name ‘serverendpoint exporter’ defined
- Idea SpringBoot:Error creating bean with name ‘XXXXController‘
- Error creating bean with name ‘org.springframework.security.oauth2.config.annotation.web.configurati
- Error creating bean with name ‘lettuceClientResources‘ defined in class path resource
- Error creating bean with name ‘sqlsessionfactory’ defined in class path resource
- About error creating bean with name ‘xxxxx’: invocation of init method