spring-boot-devtools 不同ClassLoader引起的问题
来源:互联网 发布:mac自带画图工具 编辑:程序博客网 时间:2024/06/08 19:45
在Spring Boot的文档spring-boot-devtools 部分,有如下的 描述:
By default, any open project in your IDE will be loaded using the
“restart” classloader, and any regular .jar file will be loaded using
the “base” classloader. If you work on a multi-module project, and not
each module is imported into your IDE, you may need to customize
things. To do this you can create a
META-INF/spring-devtools.properties file.The spring-devtools.properties file can contain restart.exclude. and
restart.include. prefixed properties. The include elements are items
that should be pulled up into the “restart” classloader, and the
exclude elements are items that should be pushed down into the “base”
classloader. The value of the property is a regex pattern that will be
applied to the classpath.
我遇到的问题是向上转型时出现ClassCastException,按说向上转型是不会出现这个问题的,于是想到可能是ClassLoader不一样导致的,打印了两个对象的ClassLoader,确实不同,一个RestartClassLoader,一个普通的AppClassLoader。
于是在Spring Boot DevTools的文档文档中找到上面的描述。
解决方案就是在resources目录下面创建META_INF文件夹,然后创建spring-devtools.properties文件,文件加上类似下面的配置:
restart.exclude.companycommonlibs=/mycorp-common-[\\w-]+\.jarrestart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jar
All property keys must be unique. As long as a property starts with
restart.include. or restart.exclude. it will be considered. All
META-INF/spring-devtools.properties from the classpath will be loaded.
You can package files inside your project, or in the libraries that
the project consumes.
最佳实践是将本项目中的各个模块的Jar包放到restart.include配置里面。
下面是一篇类似的文章,大家可以看下:使用Spring Boot本地启动,第三方包无法修改项目内静态常量
- spring-boot-devtools 不同ClassLoader引起的问题
- spring boot devtools
- Spring Boot devtools实例
- 使用spring-boot-devtools导致在Eclipse下的UnsatisfiedLinkError问题
- spring boot 热部署 devtools
- spring boot devtools 配置无效
- Spring-boot-devtools使用记录
- spring-boot-devtools热部署
- Spring Boot热部署spring-boot-devtools
- idea使用spring-boot-devTools无效的解决方法
- Srping Boot Devtools部署(spring-boot-devtools)
- IDEA Spring-boot-devTools 无效解决办法
- Spring Boot热部署—SpringBoot + Devtools
- 6.Spring Boot热部署之devtools
- idea+spring-boot+devtools热部署
- idea + spring-boot-devtools启动热部署
- Spring Boot 之devtools热部署
- spring boot devtools 热部署工具
- 3DSystems.Geomagic.Sculpt.2016.2.62 Ansys.OptiSLang.5.2.0.38449 Ansys.Products.18.0 win+linux Aspen.
- Hive 快速入门
- TCP-server编程
- 【机器人与小车互联项目】项目方案
- 数据存储系统的 80/20 法则
- spring-boot-devtools 不同ClassLoader引起的问题
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- volatile与synchronized的区别
- IOS图片转换格式
- TCP/IP服务器
- 利用正则表达式提取docx转为txt的文件。
- 剪贴板相关工具类
- 《C++中类对象的内存布局和占用空间》《C++ 类里面,函数占用存储空间问题 》
- 设计与实现一个视频网站——悟空视频