Skip to content

How to use @Resource annotation

Michael O'Cleirigh edited this page Apr 12, 2011 · 1 revision
  1. Add a resource reference in your web.xml descriptor, i.e.
	<env-entry>
	    <env-entry-name>welcomeMessage</env-entry-name>
	    <env-entry-type>java.lang.String</env-entry-type>
	    <env-entry-value>@Welcome</env-entry-value>
	</env-entry>
  1. Use the @Resource annotation in your wicket page, always specifing the name of the referenced resource, i.e.
public class ListContacts extends WebPage {

  @Resource(name="welcomeMessage") private String welcome;

  public ListContacts() {
    new Label(this, "welcomeMessage", welcome);
    //.......
  1. Add the line
addComponentInstantiationListener(new JavaEEComponentInjector(this));

inside the init() method of your Wicket WebApplication?, like in the example:

public class WicketJavaEEApplication extends WebApplication {

   protected void init() {
      addComponentInstantiationListener(new JavaEEComponentInjector(this));
   }
}
Clone this wiki locally