【发布时间】:2021-03-12 04:33:16
【问题描述】:
您好,我想通过手动注册 bean 而非自动 bean 来了解依赖注入。
这是自动注册 bean
@Service
public class Service {
@Autowired
private ModelMapper mapper;
}
这很简单,但我想知道我进行配置的注入
例如)..
@Configuration
public class ModelMapperConfig {
@Bean
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
modelMapper
.getConfiguration()
.setMatchingStrategy(MatchingStrategies.STRICT);
return modelMapper;
}
}
@Service
public class Service {
// i want dependency injection... !!
}
谢谢。
【问题讨论】:
-
我想通过 ModelMapperConfig 使用 ModelMapper。
标签: java spring dependency-injection dependencies