2013-06-25 52 views
0

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

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] 

我们必须手动添加弹簧安全为核心,弹簧安全-conf的依赖,当我们升级了纯Java项目中使用这个罐子,做我们需要做同样的Grails中还是有更好的方法?

Grails的2.2 Groovy的2.0.6

而且security.jar被用在Spring Security 3.0

任何指导建?我已经浏览了我们拥有的三本Grails书籍,并且没有涉及将自定义库添加到项目中的问题。

谢谢。

编辑1.

新增春季安全依赖于BuildConfig.groovy文件,如下

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文件中看到有问题的类,所以我知道它在那里。

回答

1

如果一个jar在Maven repo中不可用,并且您不能在BuildConfig.groovy中添加依赖项,则可以将其添加到lib目录中,但不会自动发现它。运行grails compile --refresh-dependencies以将其添加到类路径中。

+0

所以我添加这些 运行 “org.springframework.security:spring-security-core:3.1.4.RELEASE” 运行 “org.springframework.security:spring-security-config:3.1.4.RELEASE” 到我的BuildConfig,但它说错误未能解决。 – idonaldson

+0

无论以前的评论如何,如果你把它们放在正确的部分,它会有所帮助。我有他们在插件下,他们显然属于依赖。 – idonaldson

+0

我设法使用一个私人maven回购协议,但是当我尝试将导入添加到ApplicationContext.xml时,我得到一个ClassNotFoundException异常。在grails中导入资源是否有不同的方式? – idonaldson

相关问题