ITeye博客

spring

共 11 篇文章

使用mockMvc测试文件上传

@Autowired BanksController banksController; @TestpublicvoidtestAdd() throws IOException { RegisterConfig.RootPath = "E:\\work\\Admin"; FileInputStream fis = new FileInputStream("E:\\Images\\1.gif"); MockMultipartFile file = new MockMultipartFile("file","1.gif","image/jpeg",fis); MockMultipartHttpSe…

2017-08-20 01:52 · java · spring · junit

spring mvc 初始化加载bean

<context:component-scan base-package="com.hiway.entity"></context:component-scan> <bean name="service" class="com.hiway.entity.UserService" scope="prototype"> </bean> @Component("service") public class UserService { private User u ; public User getU() { return u; } @Resource(name="u") public void s…

2016-06-15 20:28 · java · spring · Spring

RestTemplate实践

什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率。 调用RestTemplate的默认构造函数,RestTemplate对象在底层通过使用java.net包下的实现创建HTTP 请求,可以通过使用ClientHttpRequestFactory指定不同的HTTP请求方式。 ClientHttpRequestFactory接口主要提供了两种实现方式 一种是SimpleClientHttpRequestFactory,使用J2SE提供的方式(既…

2016-06-11 00:30 · java · spring

@Component(“”)和@resource(name=””)的使用:

@Component(“”)和@resource(name=””)的使用: spring的配置文件配置: <?xml version="1.0" encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframe…

2016-06-08 01:24 · java · spring · Spring

springboot 使用外部tomcat启动

package sample.xml; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; @SuppressWarnings("deprecation") public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicati…

2016-06-05 22:59 · java · spring

spring @requestbody所需jar包

spring @requestbody所需jar包

2016-05-01 00:33 · java · spring

spring mvc配置@requestbody

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframe…

2016-05-01 00:26 · java · spring

SwaggerUI+SpringMVC——构建RestFul API的可视化界面

今天给大家介绍一款工具,这个工具目前可预见的好处是:自动维护最新的接口文档。 我们都知道,接口文档是非常重要的,但是随着代码的不断更新,文档却很难持续跟着更新,今天要介绍的工具,完美的解决了这个问题。而且,对于要使用我们接口的人来说,不需要在给他提供文档,告诉他地址,一目了然。 最近项目中一直有跟接口打交道,恰好又接触到了一个新的接口工具,拿出来跟大家分享一下。 关于REST接口,我在上篇文章中已经有介绍,这里来说一下如何配合SwaggerUI搭建RestFul API 的可视化界面。最终要达到的效果是这样的: 它可以支持Rest的所有提交方式,如POST,GET,PUT,DELETE等。 …

2016-04-25 23:29 · java · spring · Java · Spring · REST

Java开发Web Service客户端技巧:wsimport、jaxws-maven-plugin、整合Spring

搭建一个简单的Web Service服务器 要想跑Web Service客户端,前提是要有个Web Service服务器。如果你已经有Web Service服务器,那么可以跳过这一步。如果没有,可以使用JAX-WS搭建一个简单的Web Service服务器。 @WebService public class HelloWorld { public String sayHello(String name) { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = ne…

2015-12-02 20:47 · java · spring · web service

spring3 自带 cache 整合之方法缓存

spring3 自带 cache 整合之方法缓存 博客分类: spring 最近项目刚好用的spring版本是Spring3.1.M1 ,好像 spring3就开始有了对缓存的整合。其实底层的实现也就是上篇文件一样。http://m635674608.iteye.com/admin/blogs/1678983 spring3.1.M1中负责cache的模块是org.springframework.context-3.1.0.M1.jar 与2.5时的modules模块类似,3.1的注解缓存也是在方法上声明注解,3.1同样提供了两个注解: @Cacheable:负责将方法的返回值加入到缓存中 …

2014-09-04 00:55 · spring · Cache · Spring

spring-mvc

收藏该经验 现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了。不过要想灵活运用Spring MVC来应对大多数的Web开发,就必须要掌握它的配置及原理。 一、Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar包引入 Spring 2.5.6:spring.jar、spring-webmvc.jar、commons-logging.jar、cglib-nodep-2.1_3.jar Hiber…

2013-03-04 22:23 · spring · Spring