【问题标题】:How to auto-configure ConversionService in non-web Spring environment?如何在非 web Spring 环境中自动配置 ConversionService?
【发布时间】:2021-02-23 11:33:53
【问题描述】:

我有一个spring-boot 的非网络环境,因为我只需要一些类:

spring.main.web-application-type=none

问题:我如何告诉 spring 自动配置 org.springframework.core.convert.ConversionService(我需要 @Convert 自动映射 @Entity 对象)?

当我尝试自动连接对话服务时,它失败了:

@Autowired
private ConversionService conversionService;

public void fetch() {
     BeanPropertyRowMapper.newInstance(MyObject.class, conversionService));
}

required a bean of type 'org.springframework.core.convert.ConversionService' that could not be found.

【问题讨论】:

    标签: java spring spring-boot hibernate


    【解决方案1】:

    您可以自动装配 ConfigurableEnvironment 并从那里获取转换服务。如果你想直接让它可用,把它放在一个 Bean 方法中。

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 2012-07-01
      • 2015-07-14
      • 2023-04-08
      • 1970-01-01
      • 2015-06-30
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多