I'm big into CDI, but I'm not fond of application servers at all. So I'm bound to find out how to configure how to activate the CDI magic on a simple servlet container like Tomcat. That shouldn't be too difficult. Mind you, it's easy to run Weld (which happens to be the reference implementation of CDI) without a servlet container. However, in the past getting Weld on Tomcat proved to be a tad difficult, due to mediocre documentation. Luckily, that has changed. Jo Desmet (at least I suppose he's the man behind the Musings in Java blog) has published a nice walk-through to get CDI and JSF on Tomcat 8 up and running. I followed his step-by-step tutorial and managed to activate CDI on my Tomcat 8 in a couple of minutes. Highly recommended! However, no tutorial is so good it can't be improved, so let me add one or two notes on it:
context.xml
and the beans.xml
. I chose to put put into the src/main/webapp
folder. To be pedantic, the context.xml
went into the src/main/webapp/META-INF
folder, and the beans.xml
file went into the src/main/webapp/WEB-INF
folder. (From what I remember from earlier experiments, both file should also work when put into the classpath - but I didn't take the time to check this, too).