2016-03-31 25 views
0

Tutulmada basit bir web projesi oluşturmaya çalışıyorum, tomcat'i başlattıktan sonra (@RequestMapping'de belirtilen) bir yola gidebilir ve bazı işler yapabilirim. Maven yapısının kaynak dosyalarımı doğru bir şekilde derlediğini doğruladım ama Tomcat'i başlattıktan sonra, belirtilen yola gittiğimde 404 alacağım. Denetleyici sınıfımın yanı sıra benim WEB-INF/dizinindeki applicationContext ve dispatcher-servlet'i de ekledim. Sorunun haritalamayla ne olduğunu söyleyen var mı? İşte geçerli:Spring API için RequestMapping doğru haritalama değil

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.2.xsd"> 

    <context:component-scan base-package="inpowered.generator" /> 

    </beans> 

memuru-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.2.xsd"> 

    <context:component-scan base-package="inpowered.generator" /> 

</beans> 

Düzenleme/testi

@Controller 
public class IdGenerator { 
@Autowired 
private InpoweredIdDAO dao; 

@RequestMapping(value = "/getId.json", method = RequestMethod.GET) 
@ResponseBody 
public InpoweredId getId(@RequestParam String ipAddress, @RequestParam long ts,@RequestParam String agent, 
     @RequestParam String referrer) throws Exception { 
    String inpoweredId = InpoweredId.getInpoweredIdFromIp(ipAddress); 

    return dao.getImpoweredIdByIpMask(inpoweredId); 
} 

@RequestMapping(value="/test", method = RequestMethod.GET) 
public void testTomcat() { 
    System.out.println("Connected to tomcat"); 
} 

uygulama context.xml tüm varyasyonları gitmek için çalışırken ben bir 404 almak benim web.xml oldukça basit, belki sorun bu mu? Ben

<servlet> 
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
<init-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/config/web-application-config.xml</param-value> 
</init-param> 
<load-on-startup>1</load-on-startup> 

Yani bu bahar erişmekte olduğunuz url dinleyebilirsiniz herhangi yığın izini Sadece 404

<!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> 
    <display-name>Archetype Created Web Application</display-name> 
</web-app> 
+1

Web.xml dosyanızı ve ayrıca elde etmeniz durumunda stackTrace dosyanızı gönderir misiniz? – Hareesh

+0

'web.xml', istek eşlemelerinizin eklendiği temel yolu belirtmelidir. Muhtemelen temel yolu kaçırıyorsunuz, ancak lütfen onaylamak için 'web.xml' gönderin. – entpnerd

cevap

1

web.xml''deki DispatcherServlet Ekle alıyorum almıyorum

İlgili konular