काम नहीं कर रहा है एक बार जब मैं अपने टेस्ट एप्लिकेशन को उत्पादक (?) एप्लिकेशन में ले गया और टॉमकैट पर परीक्षण करना शुरू किया, तो मेरी स्प्रिंग 3.1 आधारित आरईएसटी सेवाओं ने काम करना बंद कर दिया है। हालांकि डिफ़ॉल्ट index.jsp प्रदर्शित होता है, मेरा आवेदन (http: // myhost: myport/test-webapp/myrestservice) तक पहुंचा नहीं जा सकता है और मुझे अनुरोध किया गया संसाधन (/ test-webapp/myrestservice) उपलब्ध नहीं है।जेएसओएन के साथ स्प्रिंग 3.1 आरईएसटी:
यहाँ मैं क्या किया है:
नियंत्रक:
package com.test.webapp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.test.webap.entity.Account;
@Controller
@RequestMapping("/myrestservice")
public class AccountController{
@RequestMapping(method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Account getEntity() {
// ... <simplified>
return new Account(//...);
}
}
डिस्पैच सर्वलेट विन्यास:
package com.test.webapp.web;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import com.test.webapp.config.AppConfig;
public class AppInit implements WebApplicationInitializer {
private static final String DISPATCHER_SERVLET_NAME = "dispatcher";
public void onStartup(ServletContext container) throws ServletException {
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(AppConfig.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(dispatcherContext));
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet(
DISPATCHER_SERVLET_NAME, new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
विन्यास वर्ग:
package com.test.webapp.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = {"com.test.webapp.controller"})
public class AppConfig{
// Nothing here. Once I start using the beans, I will put them here
}
और, 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>
<display-name>Test Web App</display-name>
</web-app>
मेरी परियोजना में इससे कुछ भी अलग नहीं है। क्या मैं कुछ भूल रहा हूँ? पुरानी परियोजना जो आने वाले JSON अनुरोधों आदि को लॉगिंग करने की तरह कुछ और कर रही थी (जो अब हटा दी गई है) काम कर रही थी, लेकिन मेरे पास अब यह नहीं है :(तो, बहुत से नौसिखिया ब्लूज़। कृपया मेरी मदद करें। बहुत बहुत धन्यवाद! !
अद्यतन समस्या हल हो गई है। जवाब की जाँच करें
DOCTYPE को हटाएं, यह अमान्य है - आप ऐप को बता रहे हैं कि यह एक सर्वलेट 2.3 और 3.0 संस्करण वाला ऐप है। – Pidster
मैंने उत्तर पोस्ट करने के तुरंत बाद इसे महसूस किया :-) टिप्पणी के लिए धन्यवाद। – user1323865