Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9087935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:48:36+00:00 2026-06-16T21:48:36+00:00

I am making an application in which I want to integrate Wicket + Spring.

  • 0

I am making an application in which I want to integrate Wicket + Spring. Application is a grocery store on which user comes and buy something. I know there are two ways to do this.

  1. Using the annotation aprroach. Wicket-Spring integration shows various ways on how to inject Spring Beans into Wicket pages.

    public class FormPage extends WebPage
    {
      @SpringBean
      private IContact icontact;
      ...
      Form<Object> form = new Form<Object>("contactForm",
         new CompoundPropertyModel<Object>(contact))
      {
        private static final long serialVersionUID = 1L;
    
        protected void onSubmit(Contact contact)
        {               
          icontact.saveContact(contact);
        }
      }; 
    
  2. The @SpringBean is of course valid and considered a best practice by many. But there is also another approach, where your Wicket Application has the services you need.

    public class YourWicketApp extends WebApplication{
      public static YourWicketApp get(){
        return (YourWicketApp) Application.get();
      }
      private ServiceA serviceA;
      // getter and setter for serviceA here
    }
    

    Now in your component, call

    YourWicketApp.get().getServiceA();

I want to know which is the best way to integrate spring with wicket and what are the drawbacks in each case.

However as far as I remember Wicket pages and components aren’t managed by Spring container so you cannot use @Transactional annotation on them (which is a bad idea anyway – transactions belong to deeper levels). Is this statement valid?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:48:38+00:00Added an answer on June 16, 2026 at 9:48 pm

    There are certain advantages and drawbacks for the different options. The different options are explained here. Personally, I prefer the annotation-based approach, since it guarantees proper detaching of the annotated fields and reduces the components’ dependency on the application object.

    1. Using @SpringBean

    The @SpringBean annotation is nice. It is guaranteed that the fields marked with it will not be serialized with the components. I.e., the Wicket framework “manages” the beans by nullifying the fields in each detach cycle so you don’t have to worry about it.

    The fields marked with @SpringBean are easily testable, since you can always replace them with mocks. Wicket even has a ApplicationContextMock class from which the beans will be injected when using WicketTester:

    MyComponent.java

    public class MyComponent extends Panel {
        @SpringBean
        MyServiceA myServiceA;
    }
    

    In MyComponentTest.java

    final ApplicationContextMock appContext = new ApplicationContextMock();
    appContext.putBean(mock(MyServiceA.class));
    Application app = new Application() {
        public void init() {
            ...
            getComponentInstantiationListeners().add(new SpringComponentInjector(this, appContext));
        }
    }
    WicketTester wicketTester = new WicketTester(app);
    wicketTester.startComponent(MyComponent.class);
    

    2. Using YourWicketApp.get().getServiceA()

    This is a quite lightweight approach, since it does not require binding Spring to your web application. If you’re not building a large-scale application, this might be a feasible alternative.

    The major drawback of this approach is poor testability. Since you’re accessing the application statically, you are not able to replace the application easily in tests. Of course, you can write an application YourWicketAppForTeststhat extends YourWicketApp, but you will always be restricted to that application. By doing this, you are creating a dependency from each of your service-dependent components to the application class. Furthermore, you would need a method for each of your service classes, which would add to the clutter of your application class (which, usually, is not too short in the first place).

    3. @Transactional

    The transactions definitely don’t belong to the Wicket pages and should be handled in the service layer. Since it is Wicket and not Spring that is handling the injection of beans and component instantiation, the @Transactional annotations would not work, anyway, if I’m correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am making a application in which user enter a date when he want
I'm making an application which needs the user to log in. I want to
Hi I want to try making a simple application for android phones for which
----EDIT---- I am making an jquery mobile application. Now I want to check which
I am making an application which is a user interface to access 2 types
I'm making an android application in which I want to show Punjabi text in
I am making an application in which there is a text field to enter
I am making a qt application which allows the user to select a file
I am making one rails application which is integreted with RabbiMQ. I want to
Hello i am making an small application in which i want search functionality i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.