SPRING
2018.03.12 / 01:18

°£¸¸¿¡ ¸Àº¸´Â Â¥¸´ÇÑ 404¿¡·¯! (½ºÇÁ¸µ) - tomcat spring 404

ÈÞ°í
Ãßõ ¼ö 343

¿Ã¸®½Å ÅèÄÏ¿¡ server.xml ¿¡ context ¿¡¼­ path °æ·Î ¸¦ È®ÀÎÇØÁÖ¼¼¿ä /


<Context docBase="test" path="/test" reloadable="true" source="org.eclipse.jst.j2ee.server:test"/></Host>

À§¿Í°°À̵ÇÀÖ´Ù¸é ¾Æ·¡·Î ¹Ù²ãÁÖ¼¼¿ä

<Context docBase="test" path="/" reloadable="true" source="org.eclipse.jst.j2ee.server:test"/></Host>



ÅÛÇø´¿ë ÇÁ·ÎÁ§Æ®¸¦ Çϳª ¸¸µé¾î µÎ·Á°í ±âÁ¸ ÇÁ·ÎÁ§Æ®¿¡¼­
jarÆÄÀÏµé ¿Å±â°í °£´ÜÇÏ°Ô Çϳª ¸¸µå´Â ÁßÀ̾î¿ä

±Ùµ¥ Çæ! 404 ¤Ð¤Ð
Äֿܼ¡ Å©°Ô ½É°¢ÇÑ ¿¡·¯´Â ¾È³ª¿À³×¿ä

http://localhost:8080/helloPage.do  Á¢¼ÓÇϸé
ÄÁÆ®·Ñ·¯¸¦ ¾Æ¿¹ ¸øŸ´Âµí º¸¿©¿ä
ÄÁÆ®·Ñ·¯¾È¿¡ ½Ã½ºÅÛ.¾Æ¿ô.ÇÁ¸°Æ®.¿¤¿£("hello); Çߴµ¥µµ ¾È¶°¿ä ¤Ð
´ÙÀ½Àº ÄÁÆ®·Ñ·¯¿©¿ä
package kr.co.springtemplate.controller;


@Component // ¼­ºí¸´¿¡¼­ ºóÀ¸·Î ÀÚµ¿ µî·Ï ÇÒ ¼ö ÀÖ°Ô ÄÄÆ÷³ÍÆ® Àû¿ë
@Controller // ÀÌ Å¬·¡½º°¡ ÄÁÆ®·Ñ·¯¸¦ ±¸ÇöÇÑ Å¬·¡½º¶ó´Â °ÍÀ» ÁöÁ¤
public class HelloConterller {

@Autowired
private HelloService helloService;

// @RequestMapping ¾î³ëÅ×À̼Ç: Ŭ¶óÀ̾ðÆ®ÀÇ ¿äûÀ» ó¸®ÇÒ ¸Þ¼­µå¸¦ ÁöÁ¤
// localhost:8080/ÄÁÅؽºÆ®°æ·Î/helloPage.do ¿äûÀÌ ¿À¸é helloPage()¸Þ¼­µå°¡ ó¸®
@RequestMapping("/helloPage.do")
public String helloPage(HttpServletRequest request) throws Exception{
request.setCharacterEncoding("utf-8");

System.out.println("on hello controller!");

return "helloPage";
}

¹®Á¦ ¾øÁÒ? ±×ÁÒ?
¸®Äù½ºÆ®¸ÅÇεµ È­²öÇÏ°Ô ÇØÁá°í ÀÌ°Ç ÄÁÆ®·Ñ·¯ÀÓ, ÄÄÆ÷³ÍÆ®ÀÓ ÁöÁ¤µµ ÇØÁÖ¾ú¾î¿ä

´ÙÀ½Àº µð½ºÆÐÃç.xmlÀ̾î¿ä
<context:component-scan base-package="kr.co.springtemplate" />
<!-- tiles ¼³Á¤ -->
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"></property>
</bean>

kr.co.springtemplate ÆÐÅ°Áö ¹ØÀ¸·Î »ô»ôÈ÷ µÚÁ®¼­
Çѳ𵵠³²±è¾øÀÌ ºóÀ¸·Î µî·ÏÇ϶ó°í ¾ö¸íÀ» ³»·È´Âµ¥ ž÷ÁßÀεí ÇØ¿ä

´ÙÀ½Àº web.xmlÀ̾î¿ä

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<!-- ÇÑ±Û ÀÎÄÚµù ó¸® -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern> <!-- contextPath ¹ØÀ¸·Î ¸ðµÎ -->
</filter-mapping>

<servlet>
<!-- ¼­ºí¸´ Ŭ·¡½ºÀÇ À̸§°ú ÆÐÅ°Áö °æ·Î -->
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

´ÙÀ½Àº ÅèĹÀÇ server.xml À̾î¿ä

<Context docBase="SpringTemplate" path="/SpringTemplate" reloadable="true" source="org.eclipse.jst.jee.server:SpringTemplate"/></Host>

Á¤¸» ¹®Á¦°¡ ¾ø´ÂµíÇѵ¥ ¿Ö ÄÁÆ®·Ñ·¯ Á¶Â÷ ŸÁö ¾ÊÀ»±î¿ä?
´õ¿ö¼­ ±×·±°¡?;;