在WebLogic 12.2.1上部署Spring Boot Websocket / STOMP应用程序时出错

时间:2016-04-14 00:32:43

标签: spring-boot weblogic12c

我正在创建一个Spring Boot REST API,它利用WebSockets / STOMP使用SockJS向Angular前端发送消息。我已经花了很大的力气让应用程序在WebLogic 12.2.1C中部署而不使用web.xml。我似乎很接近,但我正在使用的Spring Boot Web Socket实现存在问题。我想使用Spring Boot的实现,而不是WebLogics。当我尝试在WebLogic中部署war文件时,出现以下错误:

 <Could not load user defined filter in web.xml: weblogic.websocket.tyrus.TyrusServletFilter.
java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to org.glassfish.tyrus.server.TyrusServerContainer
        at weblogic.websocket.tyrus.TyrusServletFilter.init(TyrusServletFilter.java:76)
        at weblogic.servlet.internal.FilterManager$FilterInitAction.run(FilterManager.java:400)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:196)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
        at weblogic.servlet.internal.FilterManager.initFilter(FilterManager.java:130)
        at weblogic.servlet.internal.FilterManager.loadFilter(FilterManager.java:92)
        at weblogic.servlet.internal.FilterManager.preloadFilters(FilterManager.java:72)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1917)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3063)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1830)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:875)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)

下面是我的pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <spring.version>4.2.3.RELEASE</spring.version>
    <log4j.version>2.4.1</log4j.version>
    <apacheds.server.jndi.version>1.5.5</apacheds.server.jndi.version>
    <dao.hibernate.version>1.2.0</dao.hibernate.version>
    <commons.lang3.version>3.3.2</commons.lang3.version>
    <oracle.version>11.2.0</oracle.version>
    <hibernate.core.version>4.3.8.Final</hibernate.core.version>
    <hibernate.jpa.version>1.0.0.Final</hibernate.jpa.version>
    <httpclient.version>4.5.1</httpclient.version>
    <guava.version>19.0</guava.version>
    <spring.context.support.version>4.1.7.RELEASE</spring.context.support.version>
    <swagger.version>2.4.0</swagger.version>
    <surefire.junit47.version>2.18.1</surefire.junit47.version>
    <rest-assured.version>2.8.0</rest-assured.version>
    <hibernate.validator.version>5.1.3.Final</hibernate.validator.version>
    <jacoco.version>0.7.5.201505241946</jacoco.version>
    <tomcat.version>8.0.30</tomcat.version>
    <powermock.version>1.6.4</powermock.version>
    <spring.boot.legacy.version>1.0.1.RELEASE</spring.boot.legacy.version>
    <tomcat-jndi-scope>provided</tomcat-jndi-scope>
    <commons.io.version>2.4</commons.io.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>${tomcat-jndi-scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-dbcp</artifactId>
        <version>${tomcat.version}</version>
       <scope>${tomcat-jndi-scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-legacy</artifactId>
        <version>${spring.boot.legacy.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard.metrics</groupId>
        <artifactId>metrics-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.server</groupId>
        <artifactId>apacheds-server-jndi</artifactId>
        <version>${apacheds.server.jndi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
    <!-- -->
    <dependency>
        <groupId>com.googlecode.genericdao</groupId>
        <artifactId>dao-hibernate</artifactId>
        <version>${dao.hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>${commons.io.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons.lang3.version}</version>
    </dependency>
    <!-- ORACLE database driver MUST BE INSTALLED MANUALLY TO MAVEN, SEE README -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>${oracle.version}</version>
    </dependency>
    <!-- hibernate-->
    <!-- HIBERNATE -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.core.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <optional>true</optional>
        <version>${hibernate.jpa.version}</version>
    </dependency>
    <!-- /HIBERNATE-->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpclient.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <!-- h2 test db -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>${guava.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.context.support.version}</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>${swagger.version}</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>${swagger.version}</version>
    </dependency>

    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>${rest-assured.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>spring-mock-mvc</artifactId>
        <version>${rest-assured.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>${hibernate.validator.version}</version>
    </dependency>

</dependencies>

下面是我的weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
        xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:weblogic-version>12.2.1</wls:weblogic-version>
    <wls:context-root>app</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.joda.*</wls:package-name>
            <wls:package-name>com.google.common.*</wls:package-name>
            <wls:package-name>javax.websocket.*</wls:package-name>
            <wls:package-name>javax.websocket.server.*</wls:package-name>
            <wls:package-name>org.slf4j.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

以下是我对Spring Boot Web应用程序的入口点

@SpringBootApplication
@Import({
        WebAppConfig.class,
        CacheConfig.class,
        SwaggerConfig.class,
        HibernateOracleConfig.class
})
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

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

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

    @Override
    public void onStartup(ServletContext container) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        // <some context configuration>

        ServletRegistration.Dynamic spring = container.addServlet("Spring", new DispatcherServlet(context));
        // <some servlet configuration>

        // Here, set desired context class using 'contextClass' parameter.
        spring.setInitParameter("contextClass", context.getClass().getName());

        container.addListener(new ContextLoaderListener(context));
    }
}

如果需要更多信息,请与我们联系。我对WebLogic没什么经验,所以我不确定如何继续,任何帮助或建议肯定会受到赞赏。

我已将maven依赖项更改为以下内容...

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-websocket</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-websocket</artifactId>
    <scope>provided</scope>
</dependency>

它仍然可以作为使用mvn spring-boot:run的Spring Boot应用程序运行,如果我在WebLogic上部署时遇到任何错误,我会告诉您。

应用程序能够成功部署,但现在我有以下错误。

2016-04-14 16:16:10,304 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR o.s.boot.SpringApplication - Error handling failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined

你们之前有没有见过这个问题?

0 个答案:

没有答案