At present, we are doing springboot Project shiro session redis sharing . But there's one object that I put in redis Type mismatching exception will appear when it is taken out after

AuthorizationUser user = (AuthorizationUser) cache.getSuper(key);

Abnormal information :

java.lang.ClassCastException: com.ch.evaluation.auth.shiro.entity.AuthorizationUser cannot be cast to com.ch.evaluation.auth.shiro.entity.AuthorizationUser

adopt debug See that their class information is the same

It just looks the same ? Let me judge

The result is false ,

So we know that JVM The basis for judging whether two class objects are the same : One is the full name of a class ; One is the class loader

Since their full names are the same , So the problem must be the classloader

We can Debug Take a look at their classloaders

Sure enough , Their classloaders are different !

So what makes his classloader different ?

As we all know, the default class loading mechanism of virtual machine is implemented through parental delegation .springboot In order to achieve dynamic program ( such as : Code hot swap 、 Module hot deployment, etc , In plain language, the container does not restart after the class file is modified ),“ Destroy or sacrifice ” I've developed a parental delegation model .springboot By forcible intervention -- “ to intercept ” Loading of user-defined classes ( from jvm The loader of AppClassLoader Turn into springboot Custom loader RestartClassLoader, Once it is found that there is a file modification under the classpath ,springboot Medium spring-boot-devtools The module immediately discards the original class file and class loader , Regenerate a new class loader to load a new class file , To achieve hot deployment . More popular OSGI Hot deployment can also be achieved ).

Since the source is due to hot deployment , So just find a way to turn it off springboot Hot deployment of .

< Scheme 1 > By removing springboot Hot deployment module for spring-boot-devtools To achieve 

stay pom Note out springboot Of spring-boot-devtools

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

< Option two > If you don't want to take it off spring-boot-devtools Modules can also disable deployment features

 
 

Readers can also be in application.properties Set disable properties , But its scope only occurs in the current module , If your project involves multiple modules , It's better to disable it at the level of the whole running system through the above way , In order to avoid the inconsistency of class loaders when implementing class file calls among multiple modules .

< Option three > Since it's a class loader problem, you can also use Spring Of ConfigurableObjectInputStream coordination Thread.currentThread().getContextClassLoader() To use .

There is a type mismatch in object deserialization (spring-boot-devtools) More articles about

  1. Object storage service MinIO Install and deploy distributed and Spring Boot Project implementation file upload and download

    Catalog One .MinIO Quick start 1. MinIO brief introduction 2. CentOS7 Replace it with an alicloud image 3. install 3.1 download 3.2 Run the test 4. Configure the script execution file 4.1 Create configuration execution file 4.2 perform Two ...

  2. c# Assign an anonymous object to a Object Type of variable after , How to take this variable ? c# dynamic Dynamic types and anonymous classes Detailed explanation C# Anonymous object ( Anonymous types )、var、 Dynamic type dynamic In depth analysis of C# Medium var and dynamic

    For example, there is an anonymous object ,var  result =......Select( a=>new {  id=a.id, name=a.name}); then Object  obj =  result ; How can I ...

  3. c# Variable , object , Static type , Thread safety review of collection classes

    1. The thread safety of variables is related to the scope of variables . 2. object An object is an instance of a type When you create an object , There will be a separate memory area to store the properties and methods of the object . therefore , Multiple instances of a type , When executed , As long as there are no static variables involved , It should be thread safe ...

  4. Realize in GET Call... On request WCF Passing objects when serving ( The compound type ) Parameters

    WCF Realization RESETFUL Architecture is easy , To put it bluntly , Is to make the WCF Be able to respond to HTTP Request and return the required resources , If someone doesn't know how to do it WCF Support HTTP Requested , See my previous article < Realization jquery.ajax And the original ...

  5. Web Service Interface returns generics (System.InvalidCastException: The type cannot be “System.Collections.Generic.List`1[System.String]” Is cast to type “System.String[]”)

    In the use of C# Write Web Service I met a very strange problem when I went to work . The type of the return value is generic ( I use something like List<string>) The interface of , When testing, we find that we always report something that can't be converted to an object , puzzled . Later on ...

  6. C# Anonymous object ( Anonymous types )、var、 Dynamic type dynamic

    This article is the next one to write <C# Reflect and optimize usage > Prelude to , It's not the foundation of the next article , Interested friends can pay attention to it . With C# The development of , The voice content is constantly enriched , Development becomes more convenient and fast ,C# There's no doubt that it's sharp . ...

  7. C# Anonymous object ( Anonymous types )、var、 Dynamic type dynamic—— Practical : Filter class properties 、 Field utility dynamic

    Example Return to one LIst<oject> type and oject contain 30 A field And I just need two fields . It's practical here dynamic and linq. Code up : Be careful select new {} For anonymous type , this ...

  8. NumberFormatException: Invalid int Type mismatch exception —— Use SQL Database query statements select * from blacknumber order by _id desc limit ?,20; appear

    abnormal : Type mismatch 05-06 08:12:38.151: E/AndroidRuntime(14904): java.lang.NumberFormatException: Invalid int: ...

  9. java5 The core foundation of generics (3)- Generics work in the compile phase - How to String Object to Integer In a generic object of type ?

    Generics work in the compile phase : Generics work in the compile phase , Control type at compile time , To ensure that only the specified type data can be passed into the generic collection object when writing code . How to verify , Paste the code, such as the following : package highBasic.ge ...

Random recommendation

  1. MVC4 Do website six backstage management :6.2 Website information settings

    Used to achieve the title of the website . name . keyword . describe . Copyright and other information settings . The model field : The website's setting information should be used in front and back , So we need to model it in a way that Ninesky/Models In the folder , The code is as follows : ///////////////// ...

  2. Windows Turn on Telnet

    In order to prevent unscrupulous web crawlers from grabbing articles , This is to mark , Reprint please indicate the source of the article .LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/4301513.html ...

  3. IE Speed up plug-ins Google Chrome Frame

    Preface IE 8 And below are slower . Especially the front end js and css Especially when there are many contents . In terms of the author's development experience GWT, Ext JS, raphael , draw2d And so on IE The next use is phase ...

  4. obtain activity Root view of

    Activity What is the root view of ? Activity So called root view , Namely Activity At the bottom of View, That is to say Acitivty At the time of creation setContentView Is passed in View. How to get ...

  5. comm Usage of

    1.comm The function of Compare two sorted text files line by line :comm -[123] file1 file2 2. Example 1) Show the lines that both text files have #comm -12 file1 file2 2) display ...

  6. App Extensions Chapter Sticker Pack Extension

    Please mark the link of the original text :http://www.cnblogs.com/zhanggui/p/7151795.html Preface The last article is right App Extension It gives a brief introduction to Share Extens ...

  7. [C#] .NET Core/Standard 2.0 Compile times “CS0579: Duplicate &#39;AssemblyFileVersionAttribute&#39; attribute” The wrong solution

    author : zyl910 One . reason When creating a .NET Core/Standard 2.0 Project time ,VS Don't like .NET Framework Projects are also generated automatically AssemblyInfo.cs file . and , If it's hand made in ...

  8. Use Java Code send email

  9. [ course ]- Three spaces unicode(\u00A0,\u0020,\u3000) The difference in expression

    1. Continuous space \u00A0, Mainly used in office in , Let a word not wrap at the end , Shortcut key ctrl+shift+space ; 2. Half space ( English symbols )\u0020, Commonly used in code ; 3. Full space ( chinese ...

  10. robotium Test creation java Document and junit File differences

    There is little difference between the two , It's just that it's constructed differently , I usually use java File to create . 1. When there are source code tests , establish junit The test file ActivityInstrumentationTestCase2<T>T Sure ...