Tag: spring 4

如何使用@ResponseBody从Spring Controller返回JSON数据

Spring版本4.2.0,Hibernate 4.1.4这里是我的Controllerfunction: @RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET) @ResponseBody public List<Company> listforCompanies() { List<Company> listOfCompanies= new ArrayList<Company>(); listOfCompanies = companyManager.getAllCompanies(); return listOfCompanies; } jacksonJSON映射器依赖Pom.xml : <!– Jackson JSON Mapper –> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> 获取我的ArrayList的列表,但是当返回以下错误时显示: SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/IrApp] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: […]

Spring Boot是否意味着取代Spring Roo?

我最近花了一些时间来看看Spring 4.0生态系统中包含的项目,最近也遇到了Spring Boot的文档。 看来Boot具有很多很好的function,可以快速启动并运行Spring应用程序,包括能够以简单的.jar文件自动configuration和运行embedded式应用程序服务器。 我意识到Roo意在成为更快速地构buildSpring应用程序原型的CLI工具,并不像Boot那样采用“自以为是”的方法。 尽pipe存在这些差异,但是这两个工具的最终目标都是使Spring应用程序从头开始变得更容易,所以我的问题是:Spring Boot意味着在Spring生态系统中取代Spring Roo还是继续合作存在相同的支持水平?

当为Spring REST风格的应用程序使用ResponseEntity <T>和@RestController时

我正在使用Spring Framework 4.0.7以及MVC和Rest 我可以和平地工作: @Controller ResponseEntity<T> 例如: @Controller @RequestMapping("/person") @Profile("responseentity") public class PersonRestResponseEntityController { 用这个方法(只是为了创build) @RequestMapping(value="/", method=RequestMethod.POST) public ResponseEntity<Void> createPerson(@RequestBody Person person, UriComponentsBuilder ucb){ logger.info("PersonRestResponseEntityController – createPerson"); if(person==null) logger.error("person is null!!!"); else logger.info("{}", person.toString()); personMapRepository.savePerson(person); HttpHeaders headers = new HttpHeaders(); headers.add("1", "uno"); //http://localhost:8080/spring-utility/person/1 headers.setLocation(ucb.path("/person/{id}").buildAndExpand(person.getId()).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); } 返回一些东西 @RequestMapping(value="/{id}", method=RequestMethod.GET) public ResponseEntity<Person> getPerson(@PathVariable […]

春季4 – addResourceHandlers不parsing静态资源

下面显示了我的maven spring项目目录结构。 我正在使用Spring-4基于注释的configuration。 我configuration下面的资源。 我尝试了许多Stackoverflow问题和其他网站的build议 Spring 4加载静态资源 http://imwill.com/spring-mvc-4-add-static-resources-by-annotation/#.U5GZlXKs9i4 但是jsp文件无法加载资源,所有的静态内容请求都返回404错误。 我在jsp上试过这些东西, <link href="resources/css/bootstrap.css" rel="stylesheet" media="screen"> <link href="/resources/css/bootstrap.css" rel="stylesheet" media="screen"> <link href="css/bootstrap.css" rel="stylesheet" media="screen"> 编辑:我正在使用servlet 2.5,因为截至目前我无法将我的项目从JBoss 5升级到更高版本。 JBoss5不支持servlet 3,这是否重要? @Configuration @ComponentScan("com.mgage.mvoice") public class MyAppWebConfig extends WebMvcConfigurerAdapter { public void addResourceHandlers(ResourceHandlerRegistry registry) { // I tried these many combinations separately. ResourceHandlerRegistration resourceRegistration = registry .addResourceHandler("resources/**"); resourceRegistration.addResourceLocations("/resources/**"); registry.addResourceHandler("/css/**").addResourceLocations("/css/**"); registry.addResourceHandler("/img/**").addResourceLocations("/img/**"); […]