我有我的Spring應用程序,通過@RestController
註解提供REST API,它工作得很好。 現在我想在我的項目中集成一些View,我想使用Apache Wicket,但是我遇到了問題。我創建了WebApplication
類:配置Apache Wicket的Spring MVC中
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。
什麼網址給404?你的配置看起來不錯。 @ Mihir的答案也是有效的,但不是強制性的。您是否在日誌中看到Wicket在開發模式下啓動的消息? –
/myapp/app/Index.html 我可以看到消息 – zuno
沒有什麼配置爲「index.html的」聽。你需要使用'#mountPage(「index.html」,getHomePage())'。 –