我有两个项目A1,A2,在A2中使用
@Data
@NoArgsConstructor
public class RcConfig {
private String hh;
}
用来对一个配置文件进行定义,在A1中使用.
定义配置
rc.hh=111111111a
@Component
public class Beans {
@Bean
@ConfigurationProperties(prefix = "rc")
public RcConfig rcConfig() {
return new RcConfig();
}
}
@SpringBootApplication
@RestController
public class A1Application {
@Autowired
private RcConfig rcConfig;
public static void main(String\[\] args) {
SpringApplication.run(A1Application.class, args);
}
@GetMapping("/test")
public Object o() {
return rcConfig;
}
}
编辑一个测试类
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
class A1ApplicationTests {
@Autowired
RcConfig rcConfig;
@Test
void rc() {
Assert.assertTrue(rcConfig \== null);
System.out.println();
}
}
测试结果如下
当我启动A1项目使用http请求访问结果如下
返回确实有值出现,这是为什么?