gpt4 book ai didi

java - Spring boot war 在 Jboss 7.1 上不起作用

转载 作者:行者123 更新时间:2023-11-29 10:14:03 25 4
gpt4 key购买 nike

我正在尝试在 Jboss 上部署一个 Spring boot 应用程序。我关注this将我的 jar 转换为 war 文件的教程。但是当我尝试在 Jboss 上运行该应用程序时,它给我这个错误:

17:02:31,462 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter applicationContextIdFilter: java.lang.InstantiationException: org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextFilterConfiguration$1
at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,472 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter webRequestLoggingFilter: java.lang.InstantiationException: org.springframework.boot.actuate.trace.WebRequestTraceFilter
at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,480 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter authenticationFilter: java.lang.InstantiationException: br.gov.rs.defensoria.ldap.service.authentication.AuthenticationFilter
at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,484 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter errorPageFilter: java.lang.IllegalAccessException: Class org.jboss.as.web.deployment.WebInjectionContainer can not access a member of class org.springframework.boot.context.web.ErrorPageFilter with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109) [rt.jar:1.7.0_51]
at java.lang.Class.newInstance(Class.java:368) [rt.jar:1.7.0_51]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,493 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter metricFilter: java.lang.InstantiationException: org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter
at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,505 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Error filterStart
17:02:31,505 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Context [/ldap-service-1.0-SNAPSHOT] startup failed due to previous errors
17:02:31,510 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Closing Spring root WebApplicationContext
17:02:31,511 INFO [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (MSC service thread 1-2) Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2222014c: startup date [Thu Apr 24 17:02:23 BRT 2014]; root of context hierarchy
17:02:31,514 INFO [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-2) Stopping beans in phase 0
17:02:31,523 INFO [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter] (MSC service thread 1-2) Unregistering JMX-exposed beans on shutdown
17:02:31,529 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (MSC service thread 1-2) Closing JPA EntityManagerFactory for persistence unit 'default'
17:02:31,554 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,774 INFO [org.jboss.as.server] (HttpManagementService-threads - 1) JBAS015870: Deploy of deployment "ldap-service-1.0-SNAPSHOT.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host.\"/ldap-service-1.0-SNAPSHOT\"" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host.\"/ldap-service-1.0-SNAPSHOT\": JBAS018040: Failed to start context"}}
17:02:31,850 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment ldap-service-1.0-SNAPSHOT.war in 83ms
17:02:31,852 INFO [org.jboss.as.controller] (HttpManagementService-threads - 1) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": JBAS018040: Failed to start context

我的应用 Spring 配置文件

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

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
private static Class<Application> applicationClass = Application.class;

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
}

这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>war</packaging>
<name>myapp</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.2.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- tag::jetty[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<!-- end::jetty[] -->
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core-tiger</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.0.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<properties>
<start-class>myapp.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://dpepoaap02\SQLEXPRESS;Databasename=dev_db_ldap_service</url>
<user>user_dev</user>
<password>dpe123</password>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>localRepo</id>
<url>file://M://</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

一些想法?谢谢!

最佳答案

解释了部署 spring-boot 的主要问题 here

该帖子现在有点旧,不适用于当前的 spring-boot(撰写本文时为 1.3.3)。

你的情况是,spring-boot 执行器中的某些过滤器没有 JBoss 将尝试调用的默认构造函数,因此要解决此问题,你需要执行以下操作(这是针对当前的 spring-boot 1.3。 3):

创建一个 ApplicationContext,它将所有 bean 过滤器包装在一个具有默认构造函数的委托(delegate)类中。我们可以为此使用 spring 的 DelegatingFilterProxy

public class JBossWebApplicationContext extends AnnotationConfigEmbeddedWebApplicationContext {

private final Logger log = LoggerFactory.getLogger(getClass());

@Override
protected Collection<ServletContextInitializer> getServletContextInitializerBeans() {
Collection<ServletContextInitializer> servletContextInitializerBeans = super.getServletContextInitializerBeans();
for (ServletContextInitializer servletContextInitializerBean : servletContextInitializerBeans) {
if (servletContextInitializerBean instanceof FilterRegistrationBean) {
FilterRegistrationBean frb = (FilterRegistrationBean) servletContextInitializerBean;
try {
Field field = FilterRegistrationBean.class.getDeclaredField("filter");
field.setAccessible(true);
Filter origFilter = (Filter) field.get(frb);
frb.setFilter(new DelegatingFilterProxy(origFilter));
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new BeanCreationException("Error setting up bean. It does not have a filter field", e);
}

}
}

return servletContextInitializerBeans;
}
}

然后在您的 springboot 主类中确保使用我们在上面创建的上下文:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application.sources(MyApplication.class);
application.contextClass(JBossWebApplicationContext.class);
return super.configure(application);
}

public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setApplicationContextClass(JBossWebApplicationContext.class);
app.run(args);
}
}

最后,您需要确保您的 servlet 路径配置为“/*”,因为 JBoss 7.1 似乎无法仅使用默认值 (/)。这可以在您的 application.yml(或 application.properties)中配置

server:
servletPath: /*

这应该允许您在 JBoss 7.1 中部署一个 springBoot 应用程序(我自己在 7.1.3 上测试过)

一些额外的点:

  • 没有对此进行过广泛测试,因此在依赖此解决方案之前,您应该确保一切正常运行
  • 我真的不喜欢必须调用反射来获取 FRB 底层过滤器,但不幸的是 getFilter 方法受到保护
  • 比我更精通 spring 的人可能会改进这个解决方案

关于java - Spring boot war 在 Jboss 7.1 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23279213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com