Wicket makes it very easy to integrate directly with the Spring Framework.
In any Component (Page, Panel, etc) to include a Spring bean you would do:
@SpringBean
private MyBean myBean; |
In your application-specific Application class you would do the following:
import org.apache.wicket.spring.injection.annot.SpringComponentInjector; ... @Override protected void init { addComponentInstantiationListener(new SpringComponentInjector(this)); ... } |
If you’re using Maven for your build management, you would pull in these dependencies assuming wicket 1.3:
<dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket-spring</artifactId> <version>${wicket.version}</version> </dependency> <dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket-spring-annot</artifactId> <version>${wicket.version}</version> </dependency> |

{ 5 comments… read them below or add one }
Builds, tests and runs but when I click on the page link that uses the bean defined I get:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘masterDao’ is defined
David,
Can you provide your applicationContext.xml, web.xml, and any related code that might make sense here. The example you’ve commented on does not include a masterDao, so we’d need some context to help out.
Cheers!
How about some guide for what to put inside the web.xml and applicationContext.xml?
Just to add my Maven experience using wicket 1.4..10 and Spring 3.0.4
pom.xml file should look like this:
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-jdbc
${spring.version}
and so on.
And this:
org.apache.wicket
wicket-spring
${wicket.version}
wicket-spring-annot is not needed