Reputation: 4979
I have implemented a Java EE page which connects to an inventory webservice. I have implemented an inventory controller as shown below:
public class InventoryController {
@Autowired
private WebServiceTemplate inventoryWsTemplate;
...
}
inventoryWsTemplate is declared as a bean in web-servlet.xml.
The program works but I'm getting a warning that says:
field is used but is never assigned a non-"null" value
What should I do?
Upvotes: 2
Views: 2098
Reputation: 1503090
Just add a SuppressWarnings
annotation:
@Autowired
@SuppressWarnings("null")
private WebServiceTemplate inventoryWsTemplate;
Normally I'd add a comment to justify the annotation (e.g. // Used by guice
) but in this case coming hot on the heels of an Autowired
annotation, I don't think it's necessary.
EDIT: I can't reproduce the problem on Eclipse to start with, so I'm not sure which annotation value is required. You should check the list of supported annotation values for your compiler.
Upvotes: 3
Reputation: 488
If you don't like suppressing warnings, you can change private
to any other access modifier. Package-private probably being the best choice (besides private).
Upvotes: 1