【问题标题】:Grails resources.groovy beansGrails 资源.groovy bean
【发布时间】:2012-10-03 04:41:04
【问题描述】:

我在尝试确定我的 bean 是否已正确加载时遇到了一些问题。 是否有一些 log4j 属性可以在日志中显示正确加载了哪些 bean?。

经过一番尝试后,我开始尝试来自here 的另一个示例

重新定义我的 resources.groovy 如下:

import grails.spring.BeanBuilder
BeanBuilder bb = new BeanBuilder()
bb.beans = {
    ldapUserDetailsMapper(example.CustomDetailsContextMapper) {
    }
}

CustomDetailsContextMapper 又被定义为:

class CustomDetailsContextMapper implements UserDetailsContextMapper {
def springSecuritySource

@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection authorities) {

这是我在使用这种 resource.groovy 设置时遇到的错误:

2012-10-12 12:52:31,663 [main] ERROR spring.GrailsRuntimeConfigurator  - [RuntimeConfiguration] Unable to load beans from resources.groovy
org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: beans for class: resources
Possible solutions: class

当不使用 beanbuilder 时,我没有收到任何错误,但我无法真正验证我的 bean 是否已加载,因为它们似乎从未被调用过。 在另一种情况下,我收到以下错误。

有什么建议吗?

【问题讨论】:

    标签: grails spring-security spring-ldap


    【解决方案1】:

    在resource.groovy中简单写

    beans = {
        ldapUserDetailsMapper(example.CustomDetailsContextMapper) {
        }
    

    已经为您定义了 BeanBuilder

    一个bean在使用时被调用...在控制器中尝试一下

    VeryBeanController{
    
        def ldapUserDetailsMapper
    
        def index = {
    
           render( ldapUserDetailsMapper  )
    
        }
    
    }
    

    并调用控制器

    【讨论】:

    • 感谢这个,至少我可以验证 bean 已经加载,因为渲染提供了两个正确的对象
    猜你喜欢
    • 1970-01-01
    • 2012-04-11
    • 2014-03-17
    • 1970-01-01
    • 2012-02-22
    • 2015-12-16
    • 2016-01-23
    • 2012-02-18
    • 2012-02-23
    相关资源
    最近更新 更多