Редактировать
Итак, вы изо всех сил пытаетесь создать класс pojo для одного экземпляра с внедренным @Value.Если вы можете работать с bean-компонентом, то вот такой путь:
@Component // This will default give you a single ton bean
public class NodeMac {
@Value("${machine.network.interface}")
private String networkInterfaceName;
public String getMacAddress() {
try {
NetworkInterface network = NetworkInterface.getByName(networkInterfaceName);
byte[] mac = network.getHardwareAddress();
System.out.print("Current MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
return sb.toString();
} catch (SocketException | NullPointerException e) {
throw new RuntimeException(
"Failed to extract MAC address for network interface with name " + networkInterfaceName, e);
}
}
}
OLD
Как вы пришли к этому выражению:
String key = System.getProperty("machine.network.interface");
Маловероятно, что на машине имеется только один сетевой интерфейс, поэтому не может быть возвращен ни один ключ.
Действительно, oracle уже пишет здесь учебник
public static void main(String args[]) throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
out.printf("Display name: %s\n", netint.getDisplayName());
out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
out.printf("InetAddress: %s\n", inetAddress);
}
out.printf("\n");
}