首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用DCEVM实现热换码后常池的错误类型

用DCEVM实现热换码后常池的错误类型
EN

Stack Overflow用户
提问于 2018-10-23 15:10:16
回答 2查看 1.4K关注 0票数 0

大家好!对于上下文,我正在intelliJ中开发一个简单的spring项目,使用DCEVM 8u181 build 2和Payara 5.0应用服务器上兼容的JDK 8u181使用HotswapAgent配置它。

在接下来的几段代码片段和我对正在发生的事情的合理解释中,请原谅我,这不是一个关于Spring语法的问题,也不是它正在起作用的问题。

这是我正在热交换上测试的示例代码,不是内置在JVM上的代码,而是使用DCEVM和HotswapAgent1.3.0的代码。

HelloWorldController.java

代码语言:javascript
运行
复制
@Controller
public class HelloWorldController {



 @Autowired HelloService helloService;



@RequestMapping("/hello")
public String hello(
        @RequestParam(value = "name", required = false, defaultValue = "World") String name,
        Model model) {


    model.addAttribute("name", name);
    System.out.println( helloService.sayHello() );

    return "helloworld";
}

我不想包含helloService的代码,因为它可能会在这篇文章中膨胀。

HelloService.sayHello()只是在控制台中生成典型的Hello

正如你在上面看到的那样,自动布线已经打开,并且它完成了正确的功能(上面说过)。

在此之后,我注释掉了自动注释和函数调用,这给出了一个错误,即:

代码语言:javascript
运行
复制
org.springframework.web.util.NestedServletException: Handler dispatch     failed; nested exception is java.lang.annotation.AnnotationFormatError: java.lang.IllegalArgumentException: Wrong type at constant pool index

焦点:

代码语言:javascript
运行
复制
java.lang.IllegalArgumentException: Wrong type at constant pool index

我对应用程序进行了调试,发现当IllegalArgumentException从常量池解析Spring类的注释时,AnnotationParser被引发,而从类的常量池中提取的成员(注释的“类型”之一)是不正确的。

因此,据我所知,热部署没有得到正确的执行(即使HotswapAgent说它已经在Payara Server上重新加载了类),或者JVM通信或JDK出现了问题,我这样说是因为当我做相反的操作时,即注释掉自动部署,然后热部署,然后运行,所以我得到了一个空指针异常。

备注:只是为了补充信息,

代码语言:javascript
运行
复制
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

如果有人需要更多的信息、代码或日志,那么我将非常乐意澄清。谢谢大家抽出时间。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-25 13:22:54

解决这个问题很奇怪,但它与JDK版本或DCEVM无关,而是与Spring的dispatcher servlet有关。

我的调度程序Servlet丢失了:

代码语言:javascript
运行
复制
<annotation-driven />

这就是为什么它不能注册控制器类并导致不必要的行为。还缺少添加的XML模式。

代码语言:javascript
运行
复制
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"

为了完成任务,或者如果对任何人都有帮助,我将发布完整的dispatcher servlet配置。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <annotation-driven />

    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.test" />
    </beans:beans>
票数 0
EN

Stack Overflow用户

发布于 2018-10-23 15:24:35

Autowire的保留策略是“保留”(RetentionPolicy.RUNTIME)。

根据JVM规范,注释应该以二进制形式可用。(参考:https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.4.2)

我的假设是,java使用运行时注释将引用保存在所有类的常量池中。当您使用它时,类是热交换的,但是常量池并不是用来反映类交换的。

hotswapagent也有一个类似的未决问题:https://github.com/HotswapProjects/HotswapAgent/issues/256

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52952400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档