As I’m often looking for the correct header of the beans.xml file required for Web Beans / Context and Dependency Injection (CDI) to work, I decided to share this simple header here with you.
If you don’t have anything to declare, create an empty beans.xml like this one
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" /> If you have to declare alternatives or interceptors, do it like this <pre lang='xml'> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> <alternatives> <stereotype> com.dominikdorn.dc.passwordReset.PasswordResetService </stereotype> <class>com.dominikdorn.dc.passwordReset.StudyGuruPasswordReset</class> </alternatives> </beans> |
A good IDE will help you with creating a proper beans.xml as soon as you specify the xml namespace.
Popular implementations of CDI are