다른 블로그에서는 분명

<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" id="viewResolver" p:order="0">
2<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" id="jsonView">
3    <property name="contentType" value="application/json;charset=UTF-8">
4</property></bean>
5</bean>

이렇게 사용하라고 했지만


결론은...


HTTP Status 500 - Servlet.init() for servlet bbs threw exception

500에러가 발생한다
그 이유는 

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>


dependency를 넣지 않아서도 아니고


<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/vm/"/>
</bean>

<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".vm"/>
</bean>

<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" id="viewResolver"/>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" id="jsonView">
<property name="contentType" value="application/json;charset=UTF-8">
</property>
</bean>

왠지 velocity와 같이 사용해서 인 것같다....


그래서 다른블로그들 말만 믿고 에러만 쳐다보다가

결국 찾은 ViewResolver가 바로


<bean id="beanNameResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>


바로 InternalResourceViewResolver

이 분이다. 에러는 커녕 너무 잘 돌아가줘서 고맙다

Posted by 010562

src/main에 있던 webapp을 건드렸다 만들었다 하다가



 


webapp 디렉토리 폴더의 모양이

처음엔 위에 사진처럼 디렉토리 안에 지구(?)모양이 있었는데 




잠깐 이름바꾸면서인가?지웠다가 다시만들었는데 저 지구모양이 사라지면서

web.xml에 servlet-mapping이 에러가났다. 아래처럼




에러 내용은 저렇지만 maven에는 어느정도 다 넣었다고 생각한다.



그래서 디렉토리를 지구가 들어있는 디렉토리로 바꾸려고 해 보았지만 못찾아서...다른 메이븐+spring webapp 프로젝트를 만들어 거기있는 webapp을 복사 해 왔다.


복사 해 온 지구들어있는 디렉토리에 web.xml에서는 에러가 나지않았다.




Posted by 010562
1.pom.xml

<project xmlns="...">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.sample</groupId>
<artifactId>webservice-test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>webservice-test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

</dependencies>
<build>
<finalName>webservice-test</finalName>
</build>
</project>

2. web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns:xsi="...">
<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

3. dispatcher-servelt.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans ... >

<context:component-scan base-package="net.daum.game" ></context:component-scan>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>

<bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".vm" />
<property name="order" value="1" />
</bean>

<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/" />

</bean>
</beans>

4. velocity/myprofile.vm

<html>
<body>
Name -> $mName
<br>
Age -> $mAge
<br>
gender -> $mGender
<br>
<hr>
<br>
My name is $mName. I'm $mAge years old.

#set( $mAge = 25)

</body>
</html>

5. ProfileController

package com.company.sample;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
* Created by sm on 2016. 1. 22..
*/
@Controller
public class ProfileController {

@RequestMapping(value = "profile")
public ModelAndView ProfileView() {

ModelAndView mv =
new ModelAndView();
mv.setViewName("myprofile");
mv.addObject("mName", "sm");
mv.addObject("mAge", "24");
mv.addObject("mGender", "female");

return mv;
}
}


프로젝트 구성

(모자이크부분은 com.company.sample)


Posted by 010562