草庐IT

Servlet和springMVC

全部标签

java - Spring 无法解析 servlet 中的 View

我向我的一个servlet添加了一个新方法/映射:@RequestMapping(value="/user/prefs/order",method=RequestMethod.POST)publicvoidupdateUsersPrefs(@RequestBodyMapbody,HttpServletRequestrequest){...}但是当我向这个url发送请求时,我收到500内部服务器错误,并带有以下错误消息:javax.servlet.ServletException:Couldnotresolveviewwithname'user/prefs/order'inservlet

java - 相当于 mvc :default-servlet-handler in Spring annotation-based configuration?

是否有可能拥有的等价物?在AnnotationConfig(Web)ApplicationContext中定义?现在我有:@Configuration@ImportResource("classpath:/mvc-resources.xml")classAppConfig{//Otherconfiguration...}在我的resources/mvc-resources.xml中只有以下内容:它按预期工作。是否可以在不导入XML文件的情况下执行此操作?这将是减少一些样板的好方法。 最佳答案 如果您使用带有WebMvc的Spring

java - Spring根应用上下文和servlet上下文混淆

我知道我需要在我的servlet上下文中注册使用@Controller注释的类,以使我的web应用程序可访问。通常,我会这样做:@Configuration@EnableWebMvc@ComponentScan({"foo.bar.controller"})publicclassWebConfigextendsWebMvcConfigurerAdapter{//otherstufflikeViewResolvers,MessageResolvers,MessageConverters,etc.}我添加到我的根应用程序上下文中的所有其他配置类。这是我的调度程序初始化程序通常的样子:pub

spring - 创建 ServletContext 资源中定义的名称为 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' 的 bean 时出错

问题:我正在为执行类中的方法创建一个切入点。该类是一个Controller类,由注解@Controller表示,因此方面所需的相同不需要bean。我附上了dispathcherservlet代码、方面和Controller类。有人能找出问题所在吗。调度员伺服器:/*.htm=urlController方面:packagecom.persistent.eap.aop;importorg.aspectj.lang.ProceedingJoinPoint;importorg.aspectj.lang.annotation.Aspect;importorg.aspectj.lang.annot

java - Spring Servlet 项目的 web.xml 中加载 contextConfigLocation 的顺序

假设我有一个SpringJava项目,并且我正在尝试将其配置为Web服务器servlet。这是web.xml文件的精简版:contextConfigLocation/WEB-INF/spring/generalApplicationContext.xmlmy-servletorg.springframework.web.servlet.DispatcherServletcontextConfigLocation/WEB-INF/spring/specificApplicationContext.xml1my-servlet/foo/*这里要注意的关键是我已经指定了两个要加载的XML文件

SpringServletContainerInitializer 不能强制转换为 javax.servlet.ServletContainerInitializer

我正在尝试将基于xml的SpringMVC应用程序移动到基于Java配置的应用程序。似乎与maven中可用的各种java.servlet类不匹配。例如,有些提供addServlet()方法,有些不提供。这是我的配置类:publicclassMyWebAppInitializerimplementsWebApplicationInitializer{@OverridepublicvoidonStartup(ServletContextcontainer)throwsServletException{AnnotationConfigWebApplicationContextrootCont

spring - 何时使用 Spring @Async vs Callable Controller (异步 Controller ,servlet 3)

我想知道在Spring中使用Callable使用@Async和Servlet3异步请求实现的一般用例。据我了解,@Async用于使任何方法(特别是任何服务方法)异步执行。@AsyncvoiddoSomething(Strings){//thiswillbeexecutedasynchronously}以及任何返回Callable的Controller@RequestMapping("/view")publicCallablecallableWithView(finalModelmodel){returnnewCallable(){@OverridepublicStringcall()t

java - 原始 Servlet 与 Spring MVC

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题吗?更新问题,以便editingthispost提供事实和引用来回答它.关闭7年前。Improvethisquestion您应该使用原始JavaServlet或使用SpringMVC(或任何其他框架)构建Web应用程序的原因是什么?应该避免使用SpringMVC是否有异常(exception),使用RawServlet有什么好处? 最佳答案 如果您正在构建一个非常快速且肮脏的演示,并且您以后不打算扩展,那么Spring可能会导致许多额外的配置问题(如果您以

java - Spring 注入(inject)到 Servlet

所以我看到了这个问题:Springdependencyinjectiontootherinstance想知道我的方法是否可行。1)在我的Spring应用程序上下文中声明bean2)覆盖我的servlet的init方法,如图所示:@Overridepublicvoidinit(ServletConfigconfig)throwsServletException{super.init(config);ApplicationContextac=newClassPathXmlApplicationContext("applicationContext.xml");this.apiData=(A

spring - 从 Spring Web 应用程序中检索 servlet 上下文路径

我希望能够动态检索“servlet上下文路径”(例如http://localhost/myapp或http://www.mysite.com)用于来自Servicespringbean的SpringWeb应用程序。这样做的原因是我想在将要发送给网站用户的电子邮件中使用此值。虽然从SpringMVCController执行此操作很容易,但从Servicebean执行此操作并不那么明显。谁能给点建议?编辑:附加要求:我想知道是否有一种方法可以在应用程序启动时检索上下文路径并让我的所有服务始终可以检索它? 最佳答案 如果您使用Servle