HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.32k stars 491 forks source link

Can HotswapAgent support add @Resource/@Autowired fields in springboot based project? #495

Closed lijunjie1991 closed 6 months ago

lijunjie1991 commented 1 year ago

My project is springboot based

The code before modified like below:

@Service
public class FooServiceImpl implements FooService {

  @Resource private BarService barService;

  public void test() {
    log.info("just a test function");
  } 
  ......
}

The code after modified like below:

@Service
public class FooServiceImpl implements FooService {

  @Resource private BarService barService;
  // added a field
  @Resource private TestService testService;

  public void test() {
    log.info("just a test function: {}", testService);
  } 
  ......
}

After reload this class, and run test method, then i got the result:

just a test function: null
zzhlhc commented 1 year ago

@skybber it seems to be a dcevm issue because in IntelliJ IDEA, it shows "schema change not implemented .... Operation not supported by VM". I'm wondering if this is impossible to achieve or just requires someone to do it.

skybber commented 1 year ago

Probably you don't use dcevm or did not turn it on using -XX:-AllowEnhancedClassRedefinition

zzhlhc commented 1 year ago

I checked what you said(add -XX:-AllowEnhancedClassRedefinition), but nothing changes. If i only change method body, hot swap succeeds after rebuilding the Java file, doesn't this indicate that i'm using dcevm? BTW, i'm using jdk8 and HotSwapAgent plugin.

Whatever, you mean that dcevm theoretically supports adding fields, right?

lijunjie1991 commented 1 year ago

I checked what you said(add -XX:-AllowEnhancedClassRedefinition), but nothing changes. If i only change method body, hot swap succeeds after rebuilding the Java file, doesn't this indicate that i'm using dcevm? BTW, i'm using jdk8 and HotSwapAgent plugin.

Whatever, you mean that dcevm theoretically supports adding fields, right?

@zzhlhc I got the same error as you, and i am using jdk8 too...

schema change not implemented .... Operation not supported by VM
skybber commented 1 year ago

It's an old plugin, could you check the settings by http://hotswapagent.org/mydoc_quickstart.html ?

zzhlhc commented 1 year ago

It's an old plugin, could you check the settings by http://hotswapagent.org/mydoc_quickstart.html ?

Thanks!

It's indeed plugin's problem, i uninstalled the plugin and completed quickstart (skipped IDE specific setup guides) , then it worked well.

I think there might be more IntelliJ IDEA users are misled by this plugin...

@lijunjie1991 you can try.