You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2021/05/28 09:00:10 UTC
[wicket] branch master updated: WICKET-6889 Provide specialization
of SpringWebApplicationFactory that could load Spring configuration class
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/master by this push:
new 945cfe6 WICKET-6889 Provide specialization of SpringWebApplicationFactory that could load Spring configuration class
945cfe6 is described below
commit 945cfe620f169420b554f4c4b4659fab10a808e1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Fri May 28 11:58:23 2021 +0300
WICKET-6889 Provide specialization of SpringWebApplicationFactory that could load Spring configuration class
Introduces AnnotationConfigSpringWebApplicationFactory.
---
wicket-examples/src/main/webapp/WEB-INF/web.xml | 2 +-
...nnotationConfigSpringWebApplicationFactory.java | 49 ++++++++++++++++++++++
.../wicket/spring/SpringWebApplicationFactory.java | 20 ++++++---
3 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index 418a571..0601b97 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -396,7 +396,7 @@
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
- <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
+ <param-value>org.apache.wicket.spring.AnnotationConfigSpringWebApplicationFactory</param-value>
</init-param>
</filter>
diff --git a/wicket-spring/src/main/java/org/apache/wicket/spring/AnnotationConfigSpringWebApplicationFactory.java b/wicket-spring/src/main/java/org/apache/wicket/spring/AnnotationConfigSpringWebApplicationFactory.java
new file mode 100644
index 0000000..4d17d39
--- /dev/null
+++ b/wicket-spring/src/main/java/org/apache/wicket/spring/AnnotationConfigSpringWebApplicationFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.spring;
+
+import org.springframework.web.context.ConfigurableWebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+/**
+ * A specialization of {@link SpringWebApplicationFactory} that uses
+ * {@link AnnotationConfigWebApplicationContext}
+ *
+ * <p>
+ *
+ * <pre>
+ * <filter>
+ * <filter-name>MyApplication</filter-name>
+ * <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+ * <init-param>
+ * <param-name>applicationFactoryClassName</param-name>
+ * <param-value>org.apache.wicket.spring.AnnotationConfigSpringWebApplicationFactory</param-value>
+ * </init-param>
+ * <init-param>
+ * <param-name>contextConfigLocation</param-name>
+ * <param-value>com.example.MySpringConfig</param-value>
+ * </init-param>
+ * </filter>
+ * </pre>
+ * </p>
+ */
+public class AnnotationConfigSpringWebApplicationFactory extends SpringWebApplicationFactory {
+ @Override
+ protected ConfigurableWebApplicationContext newApplicationContext() {
+ return new AnnotationConfigWebApplicationContext();
+ }
+}
diff --git a/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java b/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
index 3d56523..773e493 100644
--- a/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
+++ b/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
@@ -18,6 +18,7 @@ package org.apache.wicket.spring;
import java.util.Map;
+import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;
import org.apache.wicket.protocol.http.IWebApplicationFactory;
@@ -109,12 +110,23 @@ public class SpringWebApplicationFactory implements IWebApplicationFactory
*/
protected final String getContextConfigLocation(final WicketFilter filter)
{
- return filter.getFilterConfig().getInitParameter("contextConfigLocation");
+ String contextConfigLocation;
+
+ final FilterConfig filterConfig = filter.getFilterConfig();
+ contextConfigLocation = filterConfig.getInitParameter("contextConfigLocation");
+
+ if (contextConfigLocation == null)
+ {
+ final ServletContext servletContext = filterConfig.getServletContext();
+ contextConfigLocation = servletContext.getInitParameter("contextConfigLocation");
+ }
+
+ return contextConfigLocation;
}
/**
* Factory method used to create a new instance of the web application context, by default an
- * instance o {@link XmlWebApplicationContext} will be created.
+ * instance of {@link XmlWebApplicationContext} will be created.
*
* @return application context instance
*/
@@ -123,9 +135,6 @@ public class SpringWebApplicationFactory implements IWebApplicationFactory
return new XmlWebApplicationContext();
}
- /**
- * @see IWebApplicationFactory#createApplication(WicketFilter)
- */
@Override
public WebApplication createApplication(final WicketFilter filter)
{
@@ -219,7 +228,6 @@ public class SpringWebApplicationFactory implements IWebApplicationFactory
// noop
}
- /** {@inheritDoc} */
@Override
public void destroy(final WicketFilter filter)
{