1

我很难弄清楚这一点。我有一个应用程序在 intellij 中运行良好,并且作为独立战争(使用创建gradlew assemble)。但是,当我尝试在 tomcat 8.5 中部署这场战争(使用gradlew assembleprovided在 build.gradle 文件中设置的 tomcat 启动器创建)时,我遇到了这个异常。但是,如果我使用生成战争,gradlew war那么我看不到这个异常,并且 tomcat 部署得很好。但在那种情况下,我的应用程序会在前端出现与 gsps 和 g: 命名空间相关的各种垃圾错误。

Caused by: java.lang.NullPointerException
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.findActionRoles(AnnotationFilterInvocationDefinition.groovy:458)
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.findAnnotations(AnnotationFilterInvocationDefinition.groovy:425)
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.findAnnotations(AnnotationFilterInvocationDefinition.groovy)
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.findControllerAnnotations(AnnotationFilterInvocationDefinition.groovy:382)
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.initialize(AnnotationFilterInvocationDefinition.groovy:223)
    at grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition$initialize.call(Unknown Source)
    at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin.initializeFromAnnotations(SpringSecurityCoreGrailsPlugin.groovy:770)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
    at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin.doWithApplicationContext(SpringSecurityCoreGrailsPlugin.groovy:651)
    at org.grails.plugins.DefaultGrailsPlugin.doWithApplicationContext(DefaultGrailsPlugin.java:523)
    at org.grails.plugins.AbstractGrailsPluginManager.doPostProcessing(AbstractGrailsPluginManager.java:224)
    at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:246)
    at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:389)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
    at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
    at org.grails.boot.context.web.GrailsAppServletInitializer.createRootApplicationContext(GrailsAppServletInitializer.groovy:57)
    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5205)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

我真的无法理解为什么会这样?这是我的application.groovy文件(安全相关配置)

grails.plugin.springsecurity.userLookup.userDomainClassName = 'my.domain.Person'
grails.plugin.springsecurity.authority.className = 'my.domain.Role'
grails.plugin.springsecurity.securityConfigType = 'Annotation' //"InterceptUrlMap"
grails.plugin.springsecurity.password.algorithm = 'MD5'
grails.plugin.springsecurity.useSecurityEventListener = true
grails.plugin.springsecurity.useSessionFixationPrevention = true
grails.plugin.springsecurity.rejectIfNoRule = true
grails.plugin.springsecurity.fii.rejectPublicInvocations = false // make this true only in dev mode. XXX
/**
 * Salting a password is a good strategy from security point of view.
 * @see  https://grails-plugins.github.io/grails-spring-security-core/v3/#salt
 */
grails.plugin.springsecurity.dao.reflectionSaltSourceProperty = 'username'
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
        [pattern: '/', access: ['permitAll']],
        [pattern: '/error/**', access: ['permitAll']],
        [pattern: '/index', access: ['permitAll']],
        [pattern: '/index.gsp', access: ['permitAll']],
        [pattern: '/shutdown', access: ['permitAll']],
        [pattern: '/assets/**', access: ['permitAll']],
        [pattern: '/**/js/**', access: ['permitAll']],
        [pattern: '/**/css/**', access: ['permitAll']],
        [pattern: '/**/images/**', access: ['permitAll']],
        [pattern: '/**/favicon.ico', access: ['permitAll']],
        [pattern: '/installrep/**', access: ['permitAll']],
        [pattern: '/status/**', access: ['permitAll']],
        [pattern: '/upgradeRepository/**', access: ['permitAll']],
        [pattern: '/patchUpgradeRepository/**', access: ['permitAll']],
        [pattern: '/log/**', access: ['permitAll']],
        [pattern: '/help/**', access: ['permitAll']],
        [pattern: '/login/**', access: ['permitAll']],
        [pattern: '/logout/**', access: ['permitAll']]
]

grails.plugin.springsecurity.filterChain.chainMap = [
        [pattern: '/assets*', filters: 'none'],
        [pattern: 'js*', filters: 'none'],
        [pattern: 'css*', filters: 'none'],
        [pattern: 'images*', filters: 'none'],
        [pattern: 'favicon.ico', filters: 'none'],
        [pattern: '/endpoints*', filters: 'JOINED_FILTERS,-filterInvocationInterceptor'],
        [pattern: '/services*', filters: 'JOINED_FILTERS,-filterInvocationInterceptor'],
        [pattern: '/**', filters: 'JOINED_FILTERS']
]

有人可以帮我理解发生了什么吗?

4

1 回答 1

1

最后,我追踪了代码。首先,grails run-app 与运行 war 的区别在于grails-core中AbstractGrailsApplication类的两个实现。对于战争,使用 DefaultGrailsApplication,而对于 intellij 等,它使用 StandaloneGrailsApplication。

这种情况下的问题是由 DefaultGrailsApplication 调用中的这个函数引起的。

public GrailsClass getArtefact(String artefactType, String name) {
    ArtefactInfo info = getArtefactInfo(artefactType);
    return info == null ? null : info.getGrailsClass(name);
}

显然,该工件正在缓存中。在 tomcat 的情况下,我在这里看到了这篇文章中提到的警告。从那篇文章中得到提示,我使用了这个答案,这确实为我解决了这个问题。我没有尝试禁用tomcat中的缓存。这可能也有帮助。如果您尝试该选项,请告诉我。

希望这可以帮助某人。我已经在这之后一个多星期了。

更新和解决方案

将 cfx 依赖项移动到 spring security 插件上方的 gradle 文件中,然后您应该会看到 spring security 只配置了一次。看到这个问题

于 2017-04-26T19:14:20.577 回答