Wicket Spring Boot Starter

repository·master·Indexed 41 days ago

https://github.com/marcgiffing/wicket-spring-boot

A Spring Boot starter providing autoconfiguration for Apache Wicket. It simplifies integration with the Spring Boot ecosystem, including Spring Security, dependency injection, and various Wicket extensions. Features include support for custom auto-configuration via wicket-spring-boot-context, version-specific configuration with @ConditionalOnWicket, and integration with datastores such as Cassandra, Redis, Hazelcast, and Memcached.

Tokens
2K
Snippets
5
Records
11
Agent score
50%

What's inside wicket-spring-boot

  1. Extend Wicket application configuration

    master

    You can add custom configuration to the Wicket WebApplication using two different approaches:

    1. Using WicketApplicationInitConfiguration

    Create a bean that implements WicketApplicationInitConfiguration and annotate it with @ApplicationInitExtension. This is ideal for modular extensions.

    2. Overriding WebApplication methods

    If you need to override core methods of the Wicket WebApplication class, create a @Component that extends one of the following:

    • WicketBootStandardWebApplication: Standard application without security.
    • WicketBootSecuredWebApplication: Application with security (requires a security provider like Spring Security).

    Your custom class will automatically be picked up instead of the default provided one.

    @ApplicationInitExtension
    public class YouExtensionConif implements WicketApplicationInitConfiguration {
    
      @Override
      public void init(WebApplication webApplication) {
      	// your custom configuration
      }
    }
  2. Create custom auto-configuration classes with wicket-spring-boot-context

    master

    Use the wicket-spring-boot-context module to build decoupled custom auto-configuration classes. This is intended for advanced users who want to create configurations without a direct dependency on the wicket-spring-boot-starter module.

    To create a valid configuration class:

    1. Mark the class with the @ApplicationInitExtension annotation.
    2. Implement the WicketApplicationInitConfiguration interface.

    All dependencies in this module are scoped as provided, ensuring that users of this module are not forced to inherit specific Spring or Wicket dependencies.

  3. Get started with Wicket and Spring Boot

    master

    To create a new Wicket project with autoconfiguration, add the wicket-spring-boot-starter dependency to your Maven configuration.

    Follow these steps:

    1. Add the dependency.
    2. Create a class annotated with @SpringBootApplication.
    3. Create your HomePage class (and corresponding HTML) and mark it with @WicketHomePage.

    An embedded Tomcat server will start automatically when you run the application.

    <dependency>
      <groupId>com.giffing.wicket.spring.boot.starter</groupId>
      <artifactId>wicket-spring-boot-starter</artifactId>
    </dependency>
  4. Configure Wicket as a WAR for Servlet Container deployment

    master

    To deploy your application as a .war file (e.g., to an external Tomcat instance):

    1. Set the packaging to war in your build tool (Maven/Gradle).
    2. Mark the spring-boot-starter-tomcat dependency as provided.
    3. Use the Spring Boot plugin to repackage the project.
    4. Extend SpringBootServletInitializer in your @SpringBootApplication class.

    Note: If you already extend a Wicket-specific class, you can create a separate class that extends SpringBootServletInitializer instead.

    @SpringBootApplication
    public class WicketApplication extends SpringBootServletInitializer  {
    
    // Can be used while developing
    public static void main(String[] args) throws Exception {
    	new SpringApplicationBuilder()
    		.sources(WicketApplication.class)
    		.run(args);
    }
    
    // Executed when deployed as a WAR in a Servlet container.
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    	builder.properties( WebSocketWicketWebInitializerAutoConfiguration.REGISTER_SERVER_ENDPOINT_ENABLED + "=false" );
    	return super.configure( builder );
    }
    
    }
  5. Configure Wicket Datastores (Cassandra, Hazelcast, Memcached, Redis)

    master

    You can use various datastores for Wicket page storage by adding the appropriate dependency and configuring the corresponding properties.

    Cassandra

    Requires wicketstuff-datastore-cassandra.

    wicket.stuff.datastore.cassandra.enabled=true
    wicket.stuff.datastore.cassandra.contact-points=host1,host2
    wicket.stuff.datastore.cassandra.table-name=pagestore
    wicket.stuff.datastore.cassandra.keyspace-name=wicket

    Redis

    Requires wicketstuff-datastore-redis.

    wicket.stuff.datastore.redis.enabled=true
    wicket.stuff.datastore.redis.port=11211

    Hazelcast

    Requires wicketstuff-datastore-hazelcast and com.hazelcast:hazelcast.

    wicket.stuff.datastore.hazelcast.enabled=true

    Memcached

    Requires wicketstuff-datastore-memcached.

    wicket.stuff.datastore.memcached.enabled=true
    wicket.stuff.datastore.memcached.port=11211
  6. Configure Wicket core settings

    master

    Wicket core settings can be configured via properties. Common settings include:

    # Mode: development or deployment (default)
    wicket.core.settings.general.configuration-type=development
    
    # Markup settings
    wicket.core.settings.markup.default-markup-encoding=UTF-8
    wicket.core.settings.markup.strip-comments=false
    
    # Request cycle settings
    wicket.core.settings.requestcycle.render-strategy=redirect-to-buffer
    
    # Exception settings
    wicket.core.settings.exceptions.error-handling-strategy-during-ajax-requests=redirect_to_error_page
  7. Configure Wicket Spring Security integration

    master

    The starter automatically detects Spring Security if spring-boot-starter-security is on the classpath. When detected, it switches to WicketBootSecuredWebApplication.

    To explicitly disable Spring Security configuration for Wicket, use:

    wicket.external.spring.security=false
    <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
  8. Configure Wicket Debug Settings

    master

    Enable debug features and development utilities using the following properties:

    wicket.core.settings.debug.enabled=true
    wicket.core.settings.debug.developmentUtilitiesEnabled=true
    wicket.core.settings.debug.ajaxDebugModeEnabled=true
    wicket.core.settings.debug.componentUseCheck=true
  9. Configure Wicket WebSockets

    master

    To enable native WebSocket support, add the wicket-native-websocket-javax dependency and set the following property:

    wicket.external.websocket=true

    When enabled, a WebSocketMessageBroadcaster bean is automatically registered. You can inject it anywhere using @SpringBean to send messages.

    <dependency>
      <groupId>org.apache.wicket</groupId>
      <artifactId>wicket-native-websocket-javax</artifactId>
    </dependency>
  10. Use Wicket special page annotations

    master

    Use these annotations to define default pages for your application:

    • @WicketHomePage: Sets the default home page. (Throws exception if multiple are found).
    • @WicketSignInPage: Sets the default login page. Requires a security provider like Spring Security.
    • @WicketAccessDeniedPage: Sets the default access denied page.
    • @WicketInternalErrorPage: Sets the default internal error page.
    • @WicketExpiredPage: Sets the default expired page.