I am trying to setup a small application with Jetty, Apache Wicket and Java 21 but it seems like my Weld DI is not picking up on the injection decorators (@Inject and @RequestScoped):
My setup is a default Wicket (maven) Quickstart (from wicket.apache.org) modified to support Java21 and ee10.
pom.xml dependency versions:
// [...] pom.xml stuff
<properties>
<wicket.version>10.1.0</wicket.version>
<slf4j.version>2.0.13</slf4j.version>
<jetty.version>12.0.7</jetty.version>
<junit.version>5.10.2</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- allowed values: R7, 1.0, 1.5, 2.0 or none -->
<wtp.version>none</wtp.version>
</properties>
<dependencies>
<!-- WICKET DEPENDENCIES -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-native-websocket-javax</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-cdi</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jakarta-server</artifactId>
<version>12.0.13</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<version>12.0.13</version>
<scope>test</scope>
</dependency>
// [...] more pom.xml stuff
And my Start.java:
public static void main(String[] args) throws Exception {
System.setProperty("wicket.configuration", "development");
Server server = new Server();
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(8443);
httpConfig.setOutputBufferSize(32768);
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
http.setPort(8080);
http.setIdleTimeout(1000 * 60 * 60);
server.addConnector(http);
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
bb.addEventListener(new Listener()); // supposedly the wicket-cdi injection?
ServletContextHandler contextHandler = ServletContextHandler.getServletContextHandler(bb.getServletContext());
JakartaWebSocketServletContainerInitializer.configure(contextHandler,
(servletContext, container) -> container.addEndpoint(new WicketServerEndpointConfig()));
server.setHandler(bb);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
server.addEventListener(mBeanContainer);
server.addBean(mBeanContainer);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
The error I am getting is:
org.jboss.weld.environment.deployment.discovery.ReflectionDiscoveryStrategy processAnnotatedDiscovery
INFO: WELD-ENV-000014: Falling back to Java Reflection for bean-discovery-mode="annotated" discovery. Add org.jboss:jandex to the classpath to speed-up startup.
org.jboss.weld.bootstrap.WeldStartup startContainer
Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
org.jboss.weld.environment.servlet.WeldServletLifecycle initialize
INFO: WELD-ENV-001001: No supported servlet container detected, CDI injection will NOT be available in Servlets, Filters or Listeners
[INFO] Session workerName=node0
[INFO] Started oeje10mp.MavenWebAppContext@1f10fec6{tractorStore,/,b=file://my-app/src/main/webapp/,a=AVAILABLE,h=oeje10s.SessionHandler@144e36ae{STARTED}}{file://my-app/src/main/webapp/}
org.jboss.weld.environment.servlet.Listener contextInitialized
INFO: WELD-ENV-001006: org.jboss.weld.environment.servlet.EnhancedListener used to initialize Weld
org.jboss.weld.environment.servlet.EnhancedListener contextInitialized
INFO: WELD-ENV-001009: org.jboss.weld.environment.servlet.Listener used for ServletRequest and HttpSession notifications
[main] INFO org.apache.wicket.util.file.WebXmlFile - web.xml: url mapping found for filter with name wicket.tractorStore: [/*]
[main] INFO org.apache.wicket.Application - [wicket.tractorStore] init: Wicket core library initializer
[main] INFO org.apache.wicket.protocol.http.WebApplication - [wicket.tractorStore] Started Wicket version 10.1.0 in DEVELOPMENT mode
and during runtime all my @Inject
classes remain null (they contain the @Named and @RequestScoped decorators).
I suspect it has something to do with:
INFO: WELD-ENV-001001: No supported servlet container detected, CDI injection will NOT be available in Servlets, Filters or Listeners
Is there anything I am missing? I have no idea what to include in my Start.java
Thanks in advance!
Edit: Never mind I found the right solution
- Add a beans.xml in your WEB-INF folder:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
- Add this in your WicketApplication.java
CdiConfiguration cdiConfiguration = new CdiConfiguration();
cdiConfiguration.configure(this);
1