使用@ConditionalOnProperty控制是否加载
public interface OSService {void os();}@ConditionalOnProperty(prefix = "custom.os", name = "name", havingValue = "linux")@Service("osService")public class Linux
·
public interface OSService {
void os();
}
@ConditionalOnProperty(prefix = "custom.os", name = "name", havingValue = "linux")
@Service("osService")
public class LinuxService implements OSService {
@Override
public void os() {
System.out.println("Now OS is Linux!");
}
}
@ConditionalOnProperty(prefix = "custom.os", name = "name", havingValue = "windows")
@Service("osService")
public class WindowsService implements OSService {
@Override
public void os() {
System.out.println("Now OS is Windows!");
}
}
@RequestMapping(path = "test")
@RestController
public class TempRestController {
@Autowired
OSService osService;
@PostMapping(path = "condition")
public void condition() {
osService.os();
}
}
配置文件 application.yml:
custom:
os:
name: linux
更多推荐
已为社区贡献2条内容
所有评论(0)