【问题标题】:Adding a custom jar to grails project将自定义 jar 添加到 grails 项目
【发布时间】:2013-06-25 17:34:08
【问题描述】:

我们有一个自定义安全 jar,它是由另一个团队基于 spring security core 和 spring security cas 构建的,我们希望将它添加到我们的 Grails 项目中。我在 applicationContext.xml 中添加了 <import resource=classpath:META-INF/security.xml> 标记并尝试添加所需的 xmlns 和 xsd 声明,但它给了我一个错误。

Message: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/security.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: class path resource [META-INF/security.xml]

当我们升级我们的纯java项目以使用这个jar时,我们不得不手动添加spring-security-core、spring-security-conf依赖项,我们需要对Grails做同样的事情还是有更好的方法?

Grails 2.2 Groovy 2.0.6

security.jar 是使用 Spring Security 3.0 构建的

有什么指导吗?我浏览了我们拥有的三本 Grails 书籍,其中没有一本涉及将自定义库添加到您的项目中。

谢谢。

编辑 1。

在 BuildConfig.groovy 文件中添加了 spring 安全依赖项,如下所示

    dependencies {
    compile "org.springframework.security:spring-security-core:3.1.4.RELEASE"
    compile "org.springframework.security:spring-security-config:3.1.4.RELEASE"
}

这似乎让我摆脱了旧的错误。但现在我越来越可爱了

Error 2013-06-25 16:20:34,982 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
Message: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [edu.umt.security.NetIdAuthoritiesPopulator] for bean with name 'userService' defined in class path resource [META-INF/security.xml]; nested exception is java.lang.ClassNotFoundException: edu.umt.security.NetIdAuthoritiesPopulator
...
Caused by CannotLoadBeanClassException: Cannot find class [edu.umt.security.NetIdAuthoritiesPopulator] for bean with name 'userService' defined in class path resource [META-INF/security.xml]; nested exception is java.lang.ClassNotFoundException: edu.umt.security.NetIdAuthoritiesPopulator

通常我们通过清理 eclipse 项目几次来解决这个问题,它会自行解决,这次没有骰子,我不确定问题出在哪里。我可以在 jar 文件中看到有问题的类,所以我知道它在那里。

【问题讨论】:

    标签: spring grails grails-2.0


    【解决方案1】:

    如果 Maven 存储库中没有可用的 jar,并且您无法在 BuildConfig.groovy 中添加依赖项,则可以将其添加到 lib 目录,但不会自动发现它。运行 grails compile --refresh-dependencies 将其添加到类路径中。

    【讨论】:

    • 所以我添加了这些运行时 "org.springframework.security:spring-security-core:3.1.4.RELEASE" 运行时 "org.springframework.security:spring-security-config:3.1.4. RELEASE”到我的 BuildConfig,但它说错误无法解决。
    • 别在意之前的评论,如果你把它们放在正确的部分会有帮助。我将它们放在插件下,它们显然属于依赖项。
    • 我设法使用私有 Maven 存储库将 jar 拉下来,但是当我尝试将导入添加到 ApplicationContext.xml 时,我得到了 ClassNotFoundException。在 grails 中导入资源有不同的方式吗?
    猜你喜欢
    • 1970-01-01
    • 2010-11-23
    • 2012-06-28
    • 2015-11-27
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    相关资源
    最近更新 更多