DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. Enhance Wicket With Spring Boot

Enhance Wicket With Spring Boot

Wicket is a good framework, but its configuration code is verbose. Fortunately, you can integrate it with Spring Boot to take advantage of its autoconfigure capabilities.

Andrea Del Bene user avatar by
Andrea Del Bene
·
Mar. 31, 17 · Tutorial
Like (6)
Save
Tweet
Share
18.40K Views

Join the DZone community and get the full member experience.

Join For Free

Wicket has traditionally provided a solid integration with the core part of Spring (i.e. the container) with its dedicated module wicket-spring. Recently, a new independent project called wicket-spring-boot has extended Spring integration to Spring Boot, too. With it, we can use Spring Boot as application starter and take advantage of its autoconfigure capabilities to set up the entire application.

To run a Wicket application with Spring Boot, we must first include the following dependency (for Maven) in our project:

<dependency>
  <groupId>com.giffing.wicket.spring.boot.starter</groupId>
  <artifactId>wicket-spring-boot-starter</artifactId>
</dependency>


Now, to run a Wicket application, we can implement a starter class like we used to do with Spring Boot:

@SpringBootApplication
public class BootApp {

    public static void main(String[] args) throws Exception {

        new SpringApplicationBuilder()
          .sources(BootApp.class)
          .run(args);
    }
}


In addition to this class, we should also specify the home page of our application by applying the annotation @WicketHomePage (the page class must be in the same application package or in a subpackage):

@WicketHomePage
public class HomePage extends WebPage {
    //...page code
}


If we run the BootApp class, we will see our home page at http://localhost:8080. As we can see, there's no trace of the Wicket application class where we override the init method to set up our web application. For this purpose, we can use the extension class WicketApplicationInitConfiguration:

@ApplicationInitExtension
public class YouExtensionConfig implements WicketApplicationInitConfiguration {

  @Override
  public void init(WebApplication webApplication) {

      //...config stuff
  }
}


In this class, we can also override the getHomePage() method if we don't want to use @WicketHomePage. If this class is not enough to configure our application, we can use WicketBootStandardWebApplication or WicketBootSecuredWebApplication (this last one is for secured applications).

To distribute our application as an executable JAR, we can simply use the Spring Boot Maven plugin:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>


Simplify Configuration With Spring Boot

During its lifetime, Wicket has seen a growing number of satellite projects aimed at extending the core framework. Most of them are hosted at WicketStuff. The configuration code for Wicket and its extensions tends to be very verbose and hard to read and mantain. With Spring Boot, we can get rid of all this code and use a simple YAML file to configure our application.

By default, Wicket Spring Boot Starter comes with a default YML configuration file for a 'development' Spring profile that can be overriden with a custom application-development.yml (under  'src/main/resources' ). Here is an example of a generic YML configuration file:

wicket.core.settings.general.configuration-type=development # development/deployment(default)
wicket.web.servlet.filter-mapping-param=/*


#Markup - Settings
wicket.core.settings.markup.default-markup-encoding=UTF-8
wicket.core.settings.markup.automatic-linking=false
wicket.core.settings.markup.compress-whitespace=false
wicket.core.settings.markup.strip-comments=false

#CSRF prevention
wicket.core.csrf.enabled=true
wicket.core.csrf.no-origin-action=allow
wicket.core.csrf.conflicting-origin-action=abort
wicket.core.csrf.error-code=400
wicket.core.csrf.error-message=Origin does not correspond to request

#datastore settings
wicket.core.datastore.httpsession.enabled=false
wicket.core.datastore.httpsession.pagesNumber=20 


Beside core parameters wicket-spring-boot also supports configuration for a number of WicketStuff modules:

#configure REST resources with restannotations
wicket.stuff.restannotations.enabled=true
wicket.stuff.restannotations.packagename= # the package name to scan for project specific annotations

#use fast 2 as serialization library
wicket.stuff.serializer.fast2.enabled=true

#use html compressor
wicket.stuff.htmlcompressor.enabled=true
wicket.stuff.htmlcompressor.features.*=


As you can see, with wicket-spring-boot, the integration between Wicket and Spring Boot is really straightforward! For more configuration options, you can see the project homepage on GitHub.

Spring Framework Spring Boot application

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Java Concurrency: LockSupport
  • Java REST API Frameworks
  • Building a REST API With AWS Gateway and Python
  • gRPC on the Client Side

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: