大家好! 对于上下文,我正在 intelliJ 中处理一个简单的 spring 项目,使用 DCEVM [8u181 build 2 ] 以及 Payara 5.0 应用程序服务器上兼容的 JDK [8u181] 使用 HotswapAgent 对其进行配置。
请在接下来的几段代码中耐心等待,以及我对正在发生的事情的合理解释,这不是关于Spring MVC语法或它正在工作的问题。
这是我在热交换[不是JVM上的内置,而是使用DCEVM]和热交换代理[1.3.0]上测试的示例代码
你好世界控制器.java
@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 World。
正如您在上面看到的,自动接线已打开,并且它执行了正确的功能(如上所述(。
在此之后,我注释掉了自动连线注释和函数调用,这给了我一个错误,即:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.annotation.AnnotationFormatError: java.lang.IllegalArgumentException: Wrong type at constant pool index
关注 :
java.lang.IllegalArgumentException: Wrong type at constant pool index
我调试了应用程序,发现当 AnnotationParser 从常量池解析 Spring Controller 类的注释时,引发了 IllegalArgumentException,并且成员(其中一个注释是注释的"类型"(在从类的常量池中获取时不正确。
因此,据我所知,热部署没有正确完成(即使HotswapAgent说它已在Payara服务器上重新加载了该类(,或者JVM通信或JDK有问题,我之所以这样说,是因为当我做相反的事情时,那就是注释掉自动布线然后热部署然后运行, 所以然后我得到一个空指针异常。
注意:仅用于补充信息
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
如果有人需要更多信息或代码或日志,那么我很乐意澄清。谢谢大家的时间。
Autowire 的保留策略是 @Retention(RetentionPolicy.RUNTIME(。
根据JVM规范,注解应该以二进制形式提供。(参考资料 : https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.4.2(
我的假设是java将引用保留在所有具有RUNTIME注释的类的常量池中。热交换时,类是热交换的,但常量池不会反映类交换。
热插拔代理也存在类似的未解决问题:https://github.com/HotswapProjects/HotswapAgent/issues/256
嗯,这很奇怪,但它与JDK版本或DCEVM无关,而是与Spring的调度程序servlet有关。
我的调度程序 Servlet 丢失了:
<annotation-driven />
这就是为什么它无法注册控制器类并导致不需要的行为。还缺少添加的 XML 架构。
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"
只是为了完成目的,或者如果对任何人都有帮助,我将发布完整的调度程序 servlet 配置。
<?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>