Hi Christian, I think you should not use use the static modifier with this, instead use:
@SpringBean private ArticleRepository repos; This should work fine and you can use it inside your constructor. Static does not add anything useful in this case, as its already a singleton in Spring. Martijn On Sat, Feb 28, 2009 at 4:49 PM, Christian Helmbold <christian.helmb...@yahoo.de> wrote: > A page in my Wicket app has a contructor which should access an injected > repository, but the repository is injected not until construction is > complete.. > > public class ArticlePage extends WebPage > { > �...@springbean > private static ArticleRepository repository; // initialized after > construction! > private Article article; > > public ArticlePage() > { > this(repository.findByName("index")); // NullPointerException here > } > > public ArticlePage(Article article) > { > add(new Label("name", new PropertyModel(article, "name"))); > add(new Label("contentHtml", new PropertyModel(article, > "contentHtml"))); > add(new Label("revision", new PropertyModel(article, "revision"))); > add(new Label("revisionDate", new PropertyModel(article, > "revisionDate"))); > add(new Label("author", new PropertyModel(article, "author"))); > } > > } > > This code looks for the default page in a database an passes it to the real > constructor. But this is only a footnote because the problem is more general. > > How do I access injected objects within a constructor? When I try to access > "repository" I get a NullPointerException because this field is initialized > after construction. The reason is that the Spring integration in Wicket does > not allow constructor injection. > > How can solve this problem? Is Wicket+Spring (or DI in general) really a good > combination? It seems again and again improper to me. > > Thanks for help! > > Christian > > -- > http://www.groovy-forum.de > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org