当前位置: 首页 > 知识库问答 >
问题:

Spring升级Tomcat vs JUnit行为

牟焱
2023-03-14

我面临一个问题,我无法将一些json转换为java对象。这个问题在这里:Spring Jackson反序列化通用对象列表。现在,我能够通过从Spring 3.0.3升级到Spring 3.2来解决这个问题。

我现在面临的问题如下。我的序列化/反序列化在我的webapp上工作得很好,但在我的单元测试上却不行。当我运行/调试它们时,我发现我遇到了与之前相同的问题(另一个stackoverflow帖子上的问题)。我想我的依赖关系一定有冲突,但花了一整天的时间调查后,我发现自己一无所有。

我的项目是一个多模块maven项目,其中依赖项有一个pom,主项目有一个pom,每个模块有一个pom。

依赖POM:

   <project>
      <name>Dependency Versions</name>
      <groupId>...</groupId>
      <artifactId>iap-dependency-versions</artifactId>
      <version>2.0.0-SNAPSHOT</version>
      <packaging>pom</packaging>
      <scm>
            <developerConnection>...</developerConnection>
      </scm>
      <distributionManagement>
      ...
      </distributionManagement>
      <properties>
            <spring.version>3.2.0.RELEASE</spring.version>
            <project.version>0.0.2-SNAPSHOT</project.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>
            <dependency>
                  <groupId>org.apache.maven.scm</groupId>
                  <artifactId>maven-scm-provider-perforce</artifactId>
                  <version>1.2</version>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-core</artifactId>
            </dependency>
            <dependency>
                  <groupId>commons-httpclient</groupId>
                  <artifactId>commons-httpclient</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-context</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-orm</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-jdbc</artifactId>
            </dependency>
            <!-- JUnit purpose  Start-->
            <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.7</version>
                  <scope>test</scope>
            </dependency>
            <dependency>
                  <groupId>commons-dbcp</groupId>
                  <artifactId>commons-dbcp</artifactId>
                  <version>1.2.2</version>
                  <scope>test</scope>
            </dependency>
            <dependency>
                  <groupId>org.aspectj</groupId>
                  <artifactId>aspectjweaver</artifactId>
                  <scope>test</scope>
            </dependency>
            <dependency>
                  <groupId>org.aspectj</groupId>
                  <artifactId>aspectjrt</artifactId>
                  <scope>test</scope>
            </dependency>
            <dependency>
                  <groupId>org.mockito</groupId>
                  <artifactId>mockito-all</artifactId>
            </dependency>
            <!-- JUnit purpose End-->
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-webmvc</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-tx</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-beans</artifactId>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-test</artifactId>
                  <scope>test</scope>
            </dependency>
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-oxm</artifactId>
                  <version>3.0.5.RELEASE</version>
            </dependency>
            <dependency>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-log4j12</artifactId>
            </dependency>
            <dependency>
                  <groupId>log4j</groupId>
                  <artifactId>log4j</artifactId>
                  <exclusions>
                        <exclusion>
                              <groupId>com.sun.jmx</groupId>
                              <artifactId>jmxri</artifactId>
                        </exclusion>
                  </exclusions>
            </dependency>
            <dependency>
                  <groupId>org.springframework.security</groupId>
                  <artifactId>spring-security-core</artifactId>
            </dependency>
      </dependencies>
      <dependencyManagement>
            <dependencies>
                  <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.7</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.core</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-provider-perforce</artifactId>
                        <version>1.2</version>
                  </dependency>
                  <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-api</artifactId>
                        <version>1.2</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-core</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-httpclient</groupId>
                        <artifactId>commons-httpclient</artifactId>
                        <version>3.1</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context</artifactId>
                        <version>${spring.version}</version>
                        <exclusions>
                              <exclusion>
                                    <groupId>commons-logging</groupId>
                                    <artifactId>commons-logging</artifactId>
                              </exclusion>
                        </exclusions>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-orm</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-jdbc</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.web.servlet</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework.ws</groupId>
                        <artifactId>org.springframework.xml</artifactId>
                        <version>1.5.5.A</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.web</artifactId>
                        <version>3.0.0.M3</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aop</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.expression</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.transaction</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.orm</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-tx</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>${spring.version}</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-test</artifactId>
                        <version>${spring.version}</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.5.8</version>
                  </dependency>
                  <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                        <version>1.5.2</version>
                  </dependency>
                  <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>jcl-over-slf4j</artifactId>
                        <version>1.5.8</version>
                        <scope>runtime</scope>
                  </dependency>
                  <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                        <version>0.9.17</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>spring-security-core</artifactId>
                        <version>2.0.3</version>
                  </dependency>
                  <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context-support</artifactId>
                        <version>3.2.0.RELEASE</version>
                  </dependency>
                  <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                        <version>3.2.5.ga</version>
                  </dependency>
                  <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-annotations</artifactId>
                        <version>3.4.0.CR1</version>
                  </dependency>
                  <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-annotations</artifactId>
                        <version>3.4.0.CR1</version>
                  </dependency>
                  <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-entitymanager</artifactId>
                        <version>3.3.2.GA</version>
                        <exclusions>
                              <exclusion>
                                    <groupId>org.hibernate</groupId>
                                    <artifactId>hibernate-commons-annotations</artifactId>
                              </exclusion>
                        </exclusions>
                  </dependency>
                  <dependency>
                        <groupId>javax.persistence</groupId>
                        <artifactId>persistence-api</artifactId>
                        <version>1.0</version>
                  </dependency>
                  <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.7</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.concordion</groupId>
                        <artifactId>concordion</artifactId>
                        <version>1.3.1</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.mockito</groupId>
                        <artifactId>mockito-all</artifactId>
                        <version>1.8.1</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.hamcrest</groupId>
                        <artifactId>hamcrest-all</artifactId>
                        <version>1.1</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.simpleframework</groupId>
                        <artifactId>simple-xml</artifactId>
                        <version>2.0.4</version>
                  </dependency>
                  <dependency>
                        <groupId>com.google.collections</groupId>
                        <artifactId>google-collections</artifactId>
                        <version>1.0-rc3</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-collections</groupId>
                        <artifactId>commons-collections</artifactId>
                        <version>3.2</version>
                  </dependency>
                  <dependency>
                        <groupId>com.google.code.findbugs</groupId>
                        <artifactId>jsr305</artifactId>
                        <version>1.3.7</version>
                        <optional>true</optional>
                  </dependency>
                  <dependency>
                        <groupId>xmlunit</groupId>
                        <artifactId>xmlunit</artifactId>
                        <version>1.2</version>
                        <scope>test</scope>
                  </dependency>
                  <dependency>
                        <groupId>net.sf.opencsv</groupId>
                        <artifactId>opencsv</artifactId>
                        <version>2.0</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-io</groupId>
                        <artifactId>commons-io</artifactId>
                        <version>1.4</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                        <version>2.4</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-codec</groupId>
                        <artifactId>commons-codec</artifactId>
                        <version>1.4</version>
                  </dependency>
                  <dependency>
                        <groupId>org.jdom</groupId>
                        <artifactId>jdom</artifactId>
                        <version>1.1</version>
                  </dependency>
                  <dependency>
                        <!-- apparently needed for jdom namespaces -->
                        <groupId>jaxen</groupId>
                        <artifactId>jaxen</artifactId>
                        <version>1.1.1</version>
                  </dependency>
                  <dependency>
                        <!-- to make concordion tests run in IntelliJ? -->
                        <groupId>xom</groupId>
                        <artifactId>xom</artifactId>
                        <version>1.1</version>
                        <scope>runtime</scope>
                  </dependency>
                  <dependency>
                        <groupId>org.apache.httpcomponents</groupId>
                        <artifactId>httpclient</artifactId>
                        <version>4.0.1</version>
                  </dependency>
                  <dependency>
                        <groupId>org.apache.httpcomponents</groupId>
                        <artifactId>httpcore</artifactId>
                        <version>4.0.1</version>
                  </dependency>
                  <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.15</version>
                        <exclusions>
                              <exclusion>
                                    <groupId>com.sun.jmx</groupId>
                                    <artifactId>jmxri</artifactId>
                              </exclusion>
                              <exclusion>
                                    <groupId>com.sun.jdmk</groupId>
                                    <artifactId>jmxtools</artifactId>
                              </exclusion>
                        </exclusions>
                  </dependency>
                  <dependency>
                        <groupId>net.sf.ehcache</groupId>
                        <artifactId>ehcache</artifactId>
                        <version>1.4.1</version>
                  </dependency>
                  <dependency>
                        <groupId>commons-dbcp</groupId>
                        <artifactId>commons-dbcp</artifactId>
                        <version>1.2.2</version>
                  </dependency>
                  <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.21</version>
                  </dependency>
                  <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>1.6.2</version>
                  </dependency>
                  <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>1.6.2</version>
                  </dependency>
                  <!--JSF -->
                  <!-- need to confirm version -->
                  <dependency>
                        <groupId>com.sun.facelets</groupId>
                        <artifactId>jsf-facelets</artifactId>
                        <version>1.1.14</version>
                  </dependency>
                  <dependency>
                        <groupId>javax.faces</groupId>
                        <artifactId>jsf-api</artifactId>
                        <version>1.2_12</version>
                  </dependency>
                  <dependency>
                        <groupId>javax.faces</groupId>
                        <artifactId>jsf-impl</artifactId>
                        <version>1.2_12</version>
                  </dependency>
                  <!-- RichFaces libraries -->
                  <dependency>
                        <groupId>org.richfaces.framework</groupId>
                        <artifactId>richfaces-api</artifactId>
                        <version>3.3.3.Final</version>
                  </dependency>
                  <dependency>
                        <groupId>org.richfaces.framework</groupId>
                        <artifactId>richfaces-impl</artifactId>
                        <version>3.3.3.Final</version>
                  </dependency>
                  <dependency>
                        <groupId>org.richfaces.ui</groupId>
                        <artifactId>richfaces-ui</artifactId>
                        <version>3.3.3.Final</version>
                  </dependency>
                  <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>servle-api</artifactId>
                        <version>2.5</version>
                        <scope>compile</scope>
                  </dependency>
                  <!-- Quartz -->
                  <dependency>
                        <groupId>quartz</groupId>
                        <artifactId>quartz</artifactId>
                        <version>1.5.2</version>
                  </dependency>
            </dependencies>
      </dependencyManagement>
      <repositories>
            <repository>
                  <id>SpringSource Enterprise Bundle Repository - External Bundle Milestones</id>
                  <url>http://repository.springsource.com/maven/bundles/milestone</url>
            </repository>
            <repository>
                  <id>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</id>
                  <url>http://repository.springsource.com/maven/bundles/release</url>
            </repository>
            <repository>
                  <id>SpringSource Enterprise Bundle Repository - External Bundle Releases</id>
                  <url>http://repository.springsource.com/maven/bundles/external</url>
            </repository>
      </repositories>
      <build>
            <plugins>
                  <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                              <argLine>-Xms768m -Xmx1024m</argLine>
                              <forkMode>never</forkMode>
                              <skip>false</skip>
                              <systemProperties>
                                    <property>
                                          <name>configDir</name>
                                          <value>${configDir}</value>
                                    </property>
                                    <property>
                                          <name>concordion.output.dir</name>
                                          <value>target/concordion</value>
                                    </property>
                              </systemProperties>
                              <excludes>
                                    <exclude>...</exclude>
                              </excludes>
                        </configuration>
                  </plugin>
            </plugins>
      </build>
   </project>

项目POM

<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>...</groupId>
    <artifactId>iap-ui</artifactId>
    <packaging>pom</packaging>
    <name>IAP UI</name>
    <description>IAP UI</description>
    <version>1.2.0-SNAPSHOT</version>
    <parent>
        <groupId>...</groupId>
        <artifactId>iap-dependency-versions</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </parent>
    <modules>
        <module>iap-common</module>
        <module>iap-model</module>
        <module>iap-persistence</module>
        <module>iap-services</module>
        <module>iap-presentation</module>
    </modules>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

战争模块POM:

<project>
    <parent>
        <groupId>...</groupId>
        <artifactId>iap-ui</artifactId>
        <version>1.2.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>iap-presentation</artifactId>
    <packaging>war</packaging>
    <name>IAP Presentation</name>
    <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- JUnit purpose Start -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- JUnit purpose Ends -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>test</scope>
        </dependency>
        <!-- RichFaces libraries -->

        <!-- Roster add end -->
        <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- Jackson JSON Mapper -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.2</version>
        </dependency>
        <!-- <dependency> <groupId>org.springframework.security</groupId> <artifactId>facelets-taglib</artifactId> 
            <version>0.1_jsf20</version> </dependency> -->
    </dependencies>
    <build>
        <finalName>iap-presentation</finalName>
    </build>
</project>

你知道为什么我的部署代码可以工作,但我的单元测试却不能工作吗?

共有1个答案

方砚
2023-03-14

您是如何部署它的?容器的lib文件夹可能包含测试范围中不可用的额外jar,因此存在类路径差异。

 类似资料:
  • 我试图将Spring security OAuth2配置从2.0.0.RC1升级到2.0.3.RELEASE。当时我从sprklr示例中复制了配置并使其工作。因此,它基于一个基于xml的Spring Security OAuth2配置的工作示例。 现在,我已经升级到Spring Security最新版本(在撰写本文时为2.0.3),并尝试将其转换为java配置。我正在下面发布xml配置和java配

  • 我需要将spring boot从2.3.7升级到2.4.1。释放。当我更新pom文件时,在spring-security-oauth2依赖项(版本2.4.1.RELEASE)中出现错误。在升级spring版本spring-security-oauth2 2.4.1之前。版本,与springboot 2.3.7配合良好。释放 我的pom文件依赖项: 当我尝试运行我的应用程序时,这是我的例外- 如何更

  • 在阅读了一些关于如何将xampp升级到新版本的php的问题后。我开始升级我的版本7因为我想学习 严格类型提示 我从官方网站下载了PHP7。我将这个下载文件夹的内容复制到xampp的php文件夹中。但它不起作用。我重新命名了php。ini开发到php。伊尼。有没有更好的方法来做到这一点,因为它不起作用。 请帮忙。

  • 我们有一个在集群中跨10个服务器运行的JEE应用程序。它利用Spring Batch(2.2.7)和Spring Batch Admin(基于1.3.0,做了一些小的修改)来每晚执行大约100个作业。批处理作业执行的控制是通过spring batch admin rest API进行的。大约一半的作业被分区,在集群中分配负载。 数据库架构更改会导致迁移现有数据时出现一些问题。 由于使用的是Spri

  • 我有一个maven java项目。SDK是Java8,现在我想升级到Java11。我还想将所有依赖项升级到最新的依赖项。这是一个spring项目(不是spring boot!!) 我可以解决所有不同的升级问题,但是在实体管理器工厂中设置持久性提供程序类时出错。 实现了 然而,方法需要一个 我有过 还有一件事对我来说很奇怪。在IntelliJ中,当我打开的类时,它说字节码版本是java 8,但是ja