我希望将Java URL
类注入到我的Spring项目中,但URL需要一个参数(您希望打开的URL)。Inject URL()Spring Autowired
我该如何去做这件事?
我现在有
private HttpURLConnection getConnectionHandler(String urlToPing) throws MalformedURLException, IOException, ProtocolException {
URL url = new URL(urlToPing);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
return connection;
}
为什么不注入属性值呢? – Leon
我无法控制这个类,它内置的URL std Java class @Leon –
只需将'String urlToPing'更改为'URL urlToPing' ... –