在Spring MVC中配置Apache Wicket

时间:2016-01-25 18:43:21

标签: java spring spring-mvc wicket

我的spring应用程序通过@RestController注释提供REST API,它运行良好。 现在我想在我的项目中集成一些View,我想使用Apache Wicket,但我遇到了问题。我创建了WebApplication类:

public class WicketApp extends WebApplication {

 @Override
 protected void init() {
    super.init();
    super.getComponentInstantiationListeners().add(new SpringComponentInjector(this));
 }

 @Override
 public Class<? extends Page> getHomePage() {
    return Index.class;
 }
}

和同一文件夹中的Index.java和Index.html文件。

但它没有用,我有404错误。这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets 
    and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<context-param>
    <param-name>contextClass</param-name>
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.myapp.AppConfig</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
    <filter-name>TestApplication</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationClassName</param-name>
        <param-value>com.myapp.web.wicket.WicketApp</param-value>
    </init-param>
</filter>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

<filter-mapping>
    <filter-name>TestApplication</filter-name>
    <url-pattern>/app/*</url-pattern>
</filter-mapping>

在我的配置文件中,我添加了此方法:

    @Configuration
    @EnableWebMvc
    @EnableTransactionManagement
    @ComponentScan({ "com.myapp.*" })
    @PropertySource(value = { "classpath:hibernate.properties" })
    public class AppConfig {

      //other configurations        

        @Bean
        public WicketApp application() {
            return new WicketApp();
        }

我真的不知道问题出在哪里......

Spring版本是4.1.4 Apache Wicket版本是7.1.0 我使用Maven。

2 个答案:

答案 0 :(得分:1)

您需要在wicket过滤器中提及Spring app配置,而不是WicketApp。

exceptionHandlers

答案 1 :(得分:1)

Wicket使用&#34; /&#34;作为主页的挂载点。如果你想另外听&#34; /index.html"然后你必须用mountPage("index.html", getHomePage())显式挂载它。