如何在grails 4项目中指定主bean

问题描述 投票:1回答:1

[我正在尝试在Grails 4中创建一个bean并将其指定为主要对象,就像我们可以在Spring中使用注解进行的操作

    @Bean
    @Primary
    public Employee TonyEmployee() {
        return new Employee("Tony");
    }

我们如何使用Grails 4?

grails
1个回答
0
投票
您可以使用BeanBuilder DSL

即指定主数据源

transactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) { bean -> dataSource = ref("dataSource") bean.primary = true }

https://docs.grails.org/4.0.1/guide/spring.html#theBeanBuilderDSLExplained
© www.soinside.com 2019 - 2024. All rights reserved.