Weblogic上的Spring MVC Rest应用程序抛出java.lang.StackOverflowError

时间:2018-11-18 05:50:38

标签: spring model-view-controller weblogic12c

我的公司正在从tomcat迁移到WebLogic 12.1.3,所以我试图在WebLogic上创建一个示例Spring MVC rest应用程序。 我从这里https://github.com/hasanozgan/spring-mvc-akka-maven-weblogic-demo克隆了一个示例项目,该项目工作正常,然后相应地修改了几个文件。

POM 将spring版本更改为4.2.1.RELEASE 添加Jackson依赖项

<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>com.hasanozgan.common</groupId>
    <artifactId>akka-demo</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Spring Akka Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>4.2.1.RELEASE</spring.version>
        <akka.version>2.3.0</akka.version>
        <scala.version>2.10</scala.version>
    </properties>
    <dependencies>
        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- AKKA Version -->
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_${scala.version}</artifactId>
            <version>${akka.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
        <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>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>com.typesafe.repo-releases</id>
            <name>Typesafe Maven Releases Repository</name>
            <url>http://repo.typesafe.com/typesafe/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <build>
        <finalName>akka-demo</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

mvc-dispatcher-servlet.xml 因为它是一个剩余应用程序,所以对InternalResourceViewResolver进行了评论。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="com.hasanozgan.demo" />
    <!-- <bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean> -->
</beans>

带有3个变量的示例数据pojo类。

    package com.hasanozgan.demo.controllers;
import java.util.Date;
public class Data {
    int rollNo;
    String name;
    Date d;
    public int getRollNo() {
        return rollNo;
    }
    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }
    public Date getD() {
        return d;
    }
    public void setD(Date d) {
        this.d = d;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

控制器 用@RestController替换@Controller并添加pojo类作为返回类型

    package com.hasanozgan.demo.controllers;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hasanozgan.demo.controllers.Data;
@RestController
@RequestMapping("/")
public class HelloController {
    @RequestMapping(method = RequestMethod.GET)
    public Data home() {
        Data d = new Data();
        d.setName("hello");
        d.setRollNo(1);
        d.setD(new Date());
        return d;
    }
}

在weblogic上部署成功,但是当我点击rest url

  

http://localhost:7001/akka-demo,有邮递员的话

Root cause of ServletException.
java.lang.StackOverflowError
    at org.springframework.context.event.AbstractApplicationEventMulticaster$ListenerCacheKey.hashCode(AbstractApplicationEventMulticaster.java:312)
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:169)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:125)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:380)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
    at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1073)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 

我在做什么错了?

0 个答案:

没有答案