条件注入Condition&feign&流web
feign @RequestMapping(value="/myTestHttp",method = RequestMethod.GET) TestReponse myFeignTest2(@RequestParam("name") String name,@RequestParam("age") String age); 接口: @RequestMapping(value = "/myTestHttp")//,method = RequestMethod.GET @ResponseBody public TestReponse myTestHttp(String name,String age){ public TestReponse myTestHttp( TestRequest request){ feign @RequestMapping(value="/myTestHttp",method = RequestMethod.GET) TestReponse myFeignTest(Map<String,Object> map); @RequestMapping(value="/myTestHttp",method = RequestMethod.POST) TestReponse myFeignTest3( TestRequest tr);//参数在@RequestBody 接口 public TestReponse myTestHttp(@RequestBody TestRequest request){ public TestReponse myTestHttp(@RequestBody Map<String,String> request){ feignClient默认参数请求类型是 header:{ 'content-type':'application/json' }, @FeignClient(value="myClient",url="http://localhost:9093",configuration = FeignConfiguration.class)// public interface MyFeignClient { @Configuration public class FeignConfiguration { @Autowired private ObjectFactory<HttpMessageConverters> messageConverters; @Bean Logger.Level feignLoggerLevel() { //这里记录所有,根据实际情况选择合适的日志level return Logger.Level.FULL; } // @Bean //待验证 // public Encoder feignFormEncoder () { // return new SpringFormEncoder(new SpringEncoder(messageConverters)); // } <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-core</artifactId> <version>9.7.0</version> </dependency> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-slf4j</artifactId> <version>9.7.0</version> </dependency> <!-非必须-> <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form</artifactId> <version>3.4.1</version> </dependency> <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form-spring</artifactId> <version>3.7.0</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.3</version> </dependency>
spring条件注入 public class MqCondition implements Condition { @Override public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { String property = conditionContext.getEnvironment().getProperty("com.dudu.name"); System.out.println("xxxxxxxxxxxxxxxxxxMqCondition:"+property); return false; } @Configuration public class MyConfig { @Bean//会导致引入方获取实例失败 @Conditional(MqCondition.class) public ServiceTest serviceTest() { System.out.println("metaPushConsumer*******************"); return new ServiceTest(); } //@Conditional(MqCondition.class) //会导致引入方获取实例失败 //@Service public class ServiceTest { }
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-core</artifactId> <version>1.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-context</artifactId> <version>1.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-commons</artifactId> <version>1.2.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> <version>1.4.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> <version>1.4.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.6.RELEASE</version> </dependency> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.7.RELEASE</version><!--1.3.7 2.0.0 2.0.4--> <relativePath/> </parent> eureka 1.3.1 eureka.client.healthcheck.enabled=true
@Headers({"Content-Type: application/x-www-form-urlencoded","Accept: application/json"})
webu层流获取
@Test public void test1() { URL u = null; try { u = new URL("http://localhost:9990/myboot/cos/hello?id=1&name=n&idCard=ic");//http://baidu.com.cn UrlResource ur = new UrlResource(u); InputStream in = ur.getInputStream(); InputStreamReader isr = new InputStreamReader(in,"gbk");// 字符输入流 Reader read = new BufferedReader(isr); //字符输入流 // ByteArrayOutputStream bao = new ByteArrayOutputStream(); // byte[] b = new byte[1024]; // int i=0; // while((i=in.read(b))>=0){//从输入流读取到字节数组 i是返回的读到b的字节个数 返回-1表示已读完 // bao.write(b);//字节数组写入输出流 // b = new byte[1024]; // } FileOutputStream fos = new FileOutputStream("mytest2.html"); OutputStreamWriter out = new OutputStreamWriter(fos); //字符输出 Writer wr = new BufferedWriter(out);// 字符输出流 char[] ch = new char[30]; int c = 0; int i = 0; while((c= read.read(ch))>=0){ //从输入流读取字符数组 //out.write(ch,0, c); //字符数组写入输出流 wr.write(ch); ch = new char[30]; System.out.println("applicant:"+ i++); } wr.flush(); wr.close(); } catch (Exception e) { e.printStackTrace(); } } @RequestMapping("/hello") // @ResponseBody public void test(User user, HttpServletRequest req, HttpServletResponse res) { System.out.println("****start "+req.getParameter("name")); logger.info("****ssstart"); System.out.println(" $$$$$ "+user); FileInputStream fis = null; Reader read = null; try { fis = new FileInputStream("mytest.html"); InputStreamReader isr = new InputStreamReader(fis,"gbk");// 字符输入流 read = new BufferedReader(isr); //字符输入流 ServletOutputStream os = res.getOutputStream(); OutputStreamWriter out = new OutputStreamWriter(os); //字符输出 Writer wr = new BufferedWriter(out);// 字符输出流 char[] ch = new char[30]; int c = 0; int i = 0; while((c= read.read(ch))>=0){ //从输入流读取字符数组 //out.write(ch,0, c); //字符数组写入输出流 wr.write(ch); ch = new char[30]; System.out.println(i++); } wr.flush(); wr.close(); } catch (Exception e) { e.printStackTrace(); } finally { //关流 } // return "hello world"; }