Grails 多个数据源: org. springframework.beans.factory.NoUniqueBeanDefinitionException

标签 grails

我最近发布了一个有关多个数据源的问题。一切进展顺利,直到我遇到这个问题:

Controller

 def doSomething() {

    def user=userService.getCurrentUser()
   }

服务

    class UserService {
     def getCurrentUser() {
        def principal = springSecurityService.principal
        String username = principal.username
        return find(username)
     }
     def find(String user) {
        return User.find{username==user}
     }
   }

这之前一直在单个数据源上工作,但现在启用了两者,我在浏览器上看到了这一点:

Error 500: Internal Server Error URI /xxx/xxx Class org.springframework.beans.factory.NoUniqueBeanDefinitionException Message No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 3: transactionManager,transactionManager_countrycity,$primaryTransactionManager

最佳答案

好的,现在问题已经解决了。

我想我发现了这个问题:在具有多个数据源的 grails 3 下,如果您有此导入:

import org.springframework.transaction.annotation.Transactional

你会遇到以上问题:

如果你曾经有:

import grails.transaction.Transactional

一切都会按预期进行。我没有注意,让ide选择了错误的声明

关于Grails 多个数据源: org. springframework.beans.factory.NoUniqueBeanDefinitionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36047346/

相关文章:

grails - 提取码头组件路线的url参数

grails - Grails-编辑-创建时不保留值

java - 在ServletContextListener中访问 session 变量

grails - war 创建时如何执行命令?

html - 如何将输入文本框添加到链接参数?

grails - Grails依赖关系和插件版本冲突

java - Grails Spring Security 密码尝试失败

Grails项目运行报错-Server failed to start for port 8080 : Address already in use: JVM_Bind

grails 和 heroku 高级 : how war and git tie together, 如果有的话

grails - 我可以使用表单的不同值反复运行 spock 测试吗?