これは私の最初の投稿ですので、気楽に行ってください。JBossAS7またはTomCat7でSpringWebMVC3.1.3を使用してJavaWebアプリケーションをセットアップしようとしています。しかし、URLマッピングで何か奇妙なことが起こっています。私はたくさんのチュートリアルに従っていますが、基本的にはこのチュートリアルのパート1を実行しようとしています。WEB-INF / viewsフォルダーに非常に単純なjspがあり、を呼び出したときにレンダリングされて返されますhttp://localhost:8080/hello/welcome
。しかし、これは起こりません。URLマッピングに問題があります。/ test / *のようなものを使用して、それを呼び出すhttp://localhost:8080/hello/test/welcome
と、期待どおりに機能します。/*を使うときhttp://localhost:8080/hello/welcome
レンダリングされていないjspを返します。そして、私がnoobの意見で使用するものをデフォルトとして使用すると、404リソースが見つかりません。これをすべて、Eclipse内で実行されているJBoss7.1.1サーバーとTomcat7.0.33サーバーでテストしたか、warファイルを使用してデプロイしました。私は私の知恵の終わりにいます。すべてのグーグル結果ページは私が探しているものをまだ見つけていない紫色のリンクでいっぱいです。
助けてくれる人はいますか?一部の情報が不足している可能性があることは理解していますが、お問い合わせください。
編集:アプリケーションのビルドにMavenを使用するのを忘れました。これは、Eclipse用のm2ewtpプラグインを使用して行われます。そして、私はEclipsejunoを実行しています。
これは私のイニシャライザーです(非常に基本的です)。
Public class Initializer implements WebApplicationInitializer
{
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.register(WebappConfig.class);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(root));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}}
これは私のWebappConfigです:
@Configuration
@ComponentScan("nl.hello")
@EnableWebMvc
public class WebappConfig extends WebMvcConfigurerAdapter
{
@Bean
public InternalResourceViewResolver setupViewResolver()
{
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer{
configurer.enable();
}}
そしてコントローラー:
@Controller
public class HelloController {
@RequestMapping("/welcome")
public String helloWorld(Model model) {
//let’s pass some variables to the view script
model.addAttribute("wisdom", "Goodbye XML");
return "welcome";
}}
そして私のpom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hello</groupId>
<artifactId>hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>utf8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
</project>