Java SpringBoot&x2B;TestNG:直接按字段读取或按方法获取之间的值不相等

Java SpringBoot&x2B;TestNG:直接按字段读取或按方法获取之间的值不相等,java,testng,Java,Testng,我使用的是SpringBoot+TestNG 复制: @Service public class DummyService { @Value("${dummy.id}") protected int id; public int getId() { return id } } application.yml dummy: id: 10 测试等级: @SpringBootTest public class Dum

我使用的是SpringBoot+TestNG

复制:

@Service
public class DummyService {
    @Value("${dummy.id}")
    protected int id;
    
    public int getId() {
        return id
    }
}
application.yml

dummy:
  id: 10
测试等级:

@SpringBootTest
public class DummyServiceTest extends AbstractTestNGSpringContextTests {
    @Autowired
    DummyService dummyService;

    @Test
    public void testGetId() {
        System.out.println(dummyService.id);     // output 0
        System.out.println(dummyService.getId);  // output 10
    }
}
为什么?? 它在JUnit中不存在。
似乎与cglib代理有关。

我很好奇您是否尝试将其公开,并查看它是否仍然为0:)