如何让Spring Boot Security和JBoss 7.1相互配合?

时间:2016-09-25 16:03:21

标签: java spring spring-boot jboss

版本:

JBoss:7.1 Spring Boot:1.4.1.RELEASE

从头开始创建一个项目并遵循从此处获取spring-boot应用程序的说明:https://spring.io/guides/gs/securing-web/,我从gradle clean bootRun开始快速轻松地运行应用程序。

但是,当我使用gradle clean war构建并部署到JBoss 7.1服务器时,在启动期间它失败并显示以下内容:

2016-09-24 18:01:37,783 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (MSC service thread 1-10)  | Exception starting filter springSecurityFilterChain: java.lang.InstantiationException: org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean$1
at java.lang.Class.newInstance(Class.java:427) [rt.jar:1.8.0_101]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-fas.jar:fas-4]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-fas.jar:fas-4]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-fas.jar:fas-4]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:91) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_101]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_101]

Caused by: java.lang.NoSuchMethodException: org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean$1.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) [rt.jar:1.8.0_101]
at java.lang.Class.newInstance(Class.java:412) [rt.jar:1.8.0_101]
... 11 more

我已经挖了好几个星期,试图从多个角度攻击它。当我一起跳过WebSecurity类并且执行@ImportResource(&#34; classpath:security-context.xml)(来自另一个工作项目)时,我收到类似的错误。稍微修改一下,我会让它再次为gradle bootRun表现,但是将它部署到JBoss会导致同样的错误。

TIA。

重要代码部分:

的build.gradle:

buildscript {
    ext {
        springBootVersion = '1.4.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'demo'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

...

dependencies {
    compile('org.springframework.boot:spring-boot-devtools')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')

    compile('org.slf4j:slf4j-api:1.7.5')

    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

DemoApplication:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class DemoApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
    return application.sources(SnapshotApiDemoApplication.class);
}

public static void main(final String[] args) {
    SpringApplication.run(SnapshotApiDemoApplication.class, args);
}
}

WebSecurityConfig:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated().and().formLogin()
            .loginPage("/login").permitAll().and().logout().permitAll();
}

@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
}

application.yml:

spring:
  main:
    banner-mode: off
    application:
      name: snapshot
      debug: true

  server:
    version: UNKNOWN
    context-path: /

application.properties:

logger.level=DEBUG
logger.handlers=FILE,CONSOLE

handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
handler.CONSOLE.level=INFO
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN

handler.FILE=org.jboss.logmanager.handlers.FileHandler
handler.FILE.level=INFO
handler.FILE.properties=autoFlush,fileName
handler.FILE.autoFlush=true
handler.FILE.fileName=demo.log
handler.FILE.formatter=PATTERN

formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n

1 个答案:

答案 0 :(得分:0)

好像您正在为SpringBoot应用程序使用JDK 1.8。

JBoss AS 7不适用于JDK8。

请参阅Unable to start jboss-as-7.1.1.Final on Windows 8.1 command prompt