Grails多个数据源:org.springframework.beans.factory.NoUniqueBeanDefinitionException [英] Grails Multiple data source: org.springframework.beans.factory.NoUniqueBeanDefinitionException

查看:766
本文介绍了Grails多个数据源:org.springframework.beans.factory.NoUniqueBeanDefinitionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



控制器

  def doSomething(){

def user = userService.getCurrentUser()
}

Service

  class UserService {
def getCurrentUser(){
def principal = springSecurityService .principal
字符串username = principal.username
返回find(用户名)
}
def find(String user){
return User.find {username == user }
}
}

以前一直在单个DataSource上工作,但现在在这两种情况下,我都会在浏览器中看到这一点:


错误500:内部服务器错误URI / xxx / xxx类
org。 springframework.beans.factory.NoUniqueBeanDefinitionException
消息没有类型
的合格bean [org.springframework.transaction.PlatformTransactionManager]是
def ined:期望单个匹配bean,但找到3:
transactionManager,transactionManager_countrycity,$ primaryTransactionManager


解决方案

好的,现在已经解决了。



我认为我发现了这个问题:如果你有这个导入,在grails 3下有多个数据源:




导入org.springframework.transaction.annotation.Transactional


您会遇到以上问题:



如果您曾经拥有过:


import grails.transaction.Transactional

事情将按预期工作。我没有注意到并让ide选择错误的声明

I recently posted a question about multiple data sources. Things were going well until I hit this issue:

Controller

 def doSomething() {

    def user=userService.getCurrentUser()
   }

Service

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

This had been working previously on single DataSource but now with both enabled I see this on the browser:

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

解决方案

Okay this is now resolved.

I think I found the issue: under grails 3 with multiple data sources if you have this import :

import org.springframework.transaction.annotation.Transactional

You will run into the above problems:

If you how ever have :

import grails.transaction.Transactional

things will work as expected. I hadn;t paid attention and let ide choose wrong declaration

这篇关于Grails多个数据源:org.springframework.beans.factory.NoUniqueBeanDefinitionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆