小编Nar*_*dey的帖子

两次调用 Class.forName()

我目前正在阅读类加载器及其层次结构功能。如果我调用下面的代码 -

ClassA a=  Class.forName("com.test.ClassA")
Run Code Online (Sandbox Code Playgroud)

根据我的理解,现在它将在应用程序类加载器的帮助下初始化并加载到内存中。我有以下问题:

  1. 如果我再次调用上面的代码会发生什么?是否会在内存中为“ClassA”创建新实例,还是会返回相同的加载类引用?
  2. 如果是,根据javarevisited 的这篇文章,“通过使用单独的 ClassLoader,您还可以从多个源加载相同的类,它们将在 JVM 中被视为不同的类” 它将有什么用?

java class classloader

3
推荐指数
1
解决办法
1326
查看次数

解决方法-JBAS014516:在5分钟内未能获得许可

我的EJB-JBOSS配置目前面临着“ JBAS014516:未能在5分钟内获得许可”的问题。下面是我的配置-

<subsystem xmlns="urn:jboss:domain:ejb3:1.4">
        <session-bean>
            <stateless>
                <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
            </stateless>
            <stateful default-access-timeout="5000" cache-ref="simple"/>
            <singleton default-access-timeout="5000"/>
        </session-bean>
        <mdb>
            <resource-adapter-ref resource-adapter-name="hornetq-ra"/>
            <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
        </mdb>
        <pools>
            <bean-instance-pools>
                <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
                <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
            </bean-instance-pools>
        </pools>
        <caches>
            <cache name="simple" aliases="NoPassivationCache"/>
            <cache name="passivating" passivation-store-ref="file" aliases="SimpleStatefulCache"/>
            <cache name="clustered" passivation-store-ref="abc" aliases="StatefulTreeCache"/>
        </caches>

        <async thread-pool-name="default"/>
        <timer-service thread-pool-name="default">
            <data-store path="timer-service-data" relative-to="jboss.server.data.dir"/>
        </timer-service>
        <remote connector-ref="remoting-connector" thread-pool-name="default"/>
        <thread-pools>
            <thread-pool name="default">
                <max-threads count="10"/>
                <keepalive-time time="100" unit="milliseconds"/>
            </thread-pool>
        </thread-pools>
        <iiop enable-by-default="false" use-qualified-name="false"/>
        <default-security-domain value="other"/>
        <default-missing-method-permissions-deny-access value="true"/>
    </subsystem>
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我应该将“ strict-max-pool”增加到一个更高的值或增加线程池的大小。

ejb threadpool ejb-3.1 jboss6.x

2
推荐指数
1
解决办法
5894
查看次数

如何为返回 PDF 文件的 Spring Boot 测试用例设置内容类型

我目前正在使用 Spring boot test 测试我的一项服务。该服务导出所有用户数据并在成功完成后生成 CSV 或 PDF。在浏览器中下载文件。

以下是我在测试类中编写的代码

MvcResult result =   MockMvc.perform(post("/api/user-accounts/export").param("query","id=='123'")
    .contentType(MediaType.APPLICATION_JSON_VALUE)
    .accept(MediaType.APPLICATION_PDF_VALUE)
    .content(TestUtil.convertObjectToJsonBytes(userObjectDTO)))
    .andExpect(status().isOk())
    .andExpect(content().contentType(MediaType.APPLICATION_PDF_VALUE))
    .andReturn();
String content = result.getResponse().getContentAsString();  // verify the response string.
Run Code Online (Sandbox Code Playgroud)

下面是我的资源类代码(调用到这个地方)-

    @PostMapping("/user-accounts/export")
@Timed
public ResponseEntity<byte[]> exportAllUsers(@RequestParam Optional<String> query, @ApiParam Pageable pageable, 
@RequestBody UserObjectDTO userObjectDTO) {
HttpHeaders headers = new HttpHeaders();
.
.
.

 return new ResponseEntity<>(outputContents, headers, HttpStatus.OK);

 }
Run Code Online (Sandbox Code Playgroud)

当我调试我的服务并在退出之前放置调试时,我得到的内容类型为“应用程序/pdf”,状态为 200。我试图在我的测试用例中复制相同的内容类型。不知何故,它在执行过程中总是抛出以下错误 -

   java.lang.AssertionError: Status 
   Expected :200
   Actual   :406
Run Code Online (Sandbox Code Playgroud)

我想知道,我应该如何检查我的响应(ResponseEntity)。还有什么应该是响应所需的内容类型。

junit spring testcase spring-boot spring-boot-test

0
推荐指数
1
解决办法
5394
查看次数