gradle war vs gradle assemble(Grails 3.2.6和Sec插件3.1.2)

时间:2017-04-24 17:55:17

标签: tomcat grails3 grails-spring-security

我很难搞清楚这个。我有一个应用程序在intellij和一个独立的战争(用gradlew assemble创建)工作正常。但是当我尝试在tomcat 8.5中部署此战争(使用provided创建但在build.gradle文件中将tomcat starter设置为gradlew war时),我收到此异常。但是如果我使用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) 生成一场战争,那么我没有看到这个异常并且tomcat部署得很好。但在这种情况下,我的应用程序在前端提供与gsps和g:namespace相关的所有类型的垃圾错误。

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'] ] 文件(安全相关配置)

{{1}}

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

1 个答案:

答案 0 :(得分:1)

最后,我追踪了代码。首先,grails run-app与运行war之间的区别归功于grails-core中的AbstractGrailsApplication类的两个实现。对于war,使用DefaultGrailsApplication,对于intellij和其他人,它使用StandaloneGrailsApplication。

在这种情况下,问题出现在DefaultGrailsApplication调用中的这个函数中。

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

显然正在查看工件缓存。在tomcat的情况下,我在这里post看到了警告。从该帖子中获取提示,我使用了this answer,这确实为我解决了这个问题。我没有尝试在tomcat中禁用缓存。这可能也有帮助。如果您尝试该选项,请告诉我。

希望这有助于某人。我已经这么做了一个多星期了。

更新和解决方案

将cfx依赖项移动到spring安全性插件上方的gradle文件中,然后您应该看到spring security仅配置一次。 See this question