jpa使用bean加载配置项

yml配置文件

com:
  aa:
    bb:
      cc:
        types:
          - name: type1
            title: 单位1
          - name: type12
            title: 单位2
          - name: type13
            title: 类型3
          - name: type14
            title:类型4

配置类

@ConfigurationProperties(prefix = "com.aa.bb.cc")
@Component
@Data
public class StatisticProperties  {

    private List<StatisticType> types;

}


@Data
public class StatisticType {
    private String name;    //类型
    private String title;   //显示
}

使用

    @Resource
    private StatisticProperties statisticProperties;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,这个错误通常是由于Spring Boot应用程序无法找到所需的DAO bean而引起的。解决此问题,可以尝试以下几种方法: 1. 确保在DAO类上使用了@Repository注解,以便Spring能够自动扫描并创建bean。 2. 确保在应用程序的@Configuration类中使用了@ComponentScan注解,以便Spring能够扫描并创建所有需要的bean。 3. 确保在DAO类中使用了@Component注解,以便Spring能够自动扫描并创建bean。 4. 确保在应用程序的@Configuration类中使用了@EnableJpaRepositories注解,以便Spring能够扫描并创建所有需要的JPA bean。 5. 确保在应用程序的@Configuration类中使用了@EnableTransactionManagement注解,以便Spring能够扫描并创建所有需要的事务bean。 6. 确保在应用程序的@Configuration类中使用了@Import注解,以便将其他配置类导入到主配置类中。 7. 确保在应用程序的@Configuration类中使用了@Bean注解,以便手动创建所需的bean。 8. 确保在应用程序的pom.xml文件中添了所需的依赖项,以便正确地所需的类和bean。 ```java // 例如: @Repository public class UserDaoImpl implements UserDao { // ... } @Service public class UserServiceImpl implements UserService { @Autowired private UserDao userDao; // ... } @Configuration @ComponentScan(basePackages = "com.example.demo") @EnableJpaRepositories(basePackages = "com.example.demo.repository") @EnableTransactionManagement public class AppConfig { // ... } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值