Tag: spring mvc

除了localhost之外,如何配置与Spring集成的嵌入式Tomcat来监听对IP地址的请求?

我试图从spring指南运行示例: 构建RESTful Web服务 。 如果我打开localhost:8080 / greeting,它会很好用。 但是,如果我打开192.168.1.111:8080/greeting或140.112.134.22:8080/greeting ,它就无法建立连接,尽管我的计算机实际上在互联网上使用了这两个IP。 有人可以建议我如何在Spring中配置嵌入式Tomcat以接受其他IP地址上的HTTP请求,除了localhost(即127.0.0.1)? 谢谢! 🙂

如何在带有注释映射的Spring MVC中使用不区分大小写的URL

通过我的spring mvc web应用程序,我有注释的映射工作,但是,它们区分大小写。 我找不到让它们不区分大小写的方法。 (我很想在Spring MVC中实现这一点,而不是以某种方式重定向流量)

手动调用Spring Annotation Validation

我正在使用Hibernate和Spring Annotations进行大量validation,如下所示: public class Account { @NotEmpty(groups = {Step1.class, Step2.class}) private String name; @NotNull(groups = {Step2.class}) private Long accountNumber; public interface Step1{} public interface Step2{} } 然后在控制器中调用它: public String saveAccount(@ModelAttribute @Validated({Account.Step1.class}) Account account, BindingResult result) { //some more code and stuff here return “”; } 但我想根据控制器方法中的一些逻辑来决定使用的组。 有没有办法手动调用validation? 像result = account.validate(Account.Step1.class) ? 我知道创建自己的Validator类,但这是我想要避免的,我宁愿只使用类变量本身的注释。

在Spring MVC中将参数从JSP传递到Controller

我正在尝试使用Spring MVC带注释的控制器的示例项目。 到目前为止,我在网上找到的所有示例都将JSP绑定到特定模型,控制器使用@ModelAttribute来检索处理程序方法中的模型对象。 如何将其他参数(不存在于Model对象中)从JSP传递给Controller? 我是否使用JavaScript来执行此操作? 也有人可以澄清HttpServletRequest对象应该用于什么。 谢谢。

带有内容类型application / x-www-form-urlencoded的Http Post请求在Spring中不起作用

我是spring的新手,我正在尝试做HTTP POST请求应用程序/ x-www-form-url编码 ,但当我把它保存在我的标题中然后spring不认识它并且说x-www-form-urlencoded 415 Unsupported Media Type org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型’application / x-www-form-urlencoded’ 任何人都知道如何解决它吗? 请评论我。 我的控制器的一个例子是: @RequestMapping(value = “/patientdetails”, method = RequestMethod.POST, headers=”Accept=application/x-www-form-urlencoded”) public @ResponseBody List getPatientDetails( @RequestBody PatientProfileDto name) { List list = new ArrayList(); list = service.getPatient(name); return list; }

Spring MVC – AngularJS – 文件上传 – org.apache.commons.fileupload.FileUploadException

我有一个Java Spring MVC Web应用程序作为服务器。 而基于AngularJS的应用程序作为客户端。 在AngularJS中,我必须上传文件并发送到服务器。 这是我的HTML Submit 这是我的UploadController.js ‘use strict’; var mainApp=angular.module(‘mainApp’, [‘ngCookies’]); mainApp.controller(‘FileUploadController’, function($scope, $http) { $scope.document = {}; $scope.setTitle = function(fileInput) { var file=fileInput.value; var filename = file.replace(/^.*[\\\/]/, ”); var title = filename.substr(0, filename.lastIndexOf(‘.’)); $(“#title”).val(title); $(“#title”).focus(); $scope.document.title=title; }; $scope.uploadFile=function(){ var formData=new FormData(); formData.append(“file”,file.files[0]); $http({ method: ‘POST’, url: ‘/serverApp/rest/newDocument’, headers: { ‘Content-Type’: ‘multipart/form-data’}, […]

在春季测试中请求范围豆

我想在我的应用程序中使用请求范围的bean。 我使用JUnit4进行测试。 如果我尝试在这样的测试中创建一个: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { “classpath:spring/TestScopedBeans-context.xml” }) public class TestScopedBeans { protected final static Logger logger = Logger .getLogger(TestScopedBeans.class); @Resource private Object tObj; @Test public void testBean() { logger.debug(tObj); } @Test public void testBean2() { logger.debug(tObj); } 使用以下bean定义: 我得到: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘gov.nasa.arc.cx.sor.query.TestScopedBeans’: Injection of resource fields failed; nested exception […]

如何处理MaxUploadSizeExceededException

当我上传大小超过允许的最大值的文件时,会出现MaxUploadSizeExceededExceptionexception。 我想在出现此exception时显示错误消息(如validation错误消息)。 如何在Spring 3中处理此exception以执行此类操作? 谢谢。

必须Spring MVC类是线程安全的

如果使用Spring MVC,那么组件类( @Controller @Service , @Repository @Controller , @Service @Repository )必须是线程安全的吗? 也就是说,如果我的@Controller有一个@RequestMapping方法,是否可以通过多个线程同时为同一个控制器对象调用该方法? ( 之前已经提到了这种情况,但没有得到回答)。

spring web,security + web.xml + mvc dispatcher + Bean创建两次

我有如下的Web.xml: mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1 mvc-dispatcher / springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /api/secure/* [编辑] 在我添加了spring security后,我收到了错误! java.lang.IllegalStateException:找不到WebApplicationContext:没有注册ContextLoaderListener? 然后我补充道 contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener 然后它似乎工作正常,但然后1)问题是豆被创建两次! 如果我只删除它: contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml 但是留下然后Web应用程序根本不运行 [额外] 完整的Web.xml如下: Spring MVC Application mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1 mvc-dispatcher / springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /api/secure/* contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener 这是我的mvc-dispatcher-servlet.xml