1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      spring-boot之一:簡單入門

      1.在IDE中創(chuàng)建一個web項(xiàng)目

      東風(fēng)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,東風(fēng)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為東風(fēng)近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的東風(fēng)做網(wǎng)站的公司定做!

      spring-boot之一:簡單入門spring-boot之一:簡單入門

      2.在pom.xml文件中增加maven依賴

         org.springframework.boot

         spring-boot-starter-parent

         1.5.9.RELEASE

         

             org.springframework.boot

             spring-boot-starter-web

         

      spring-boot之一:簡單入門spring-boot之一:簡單入門

      3.創(chuàng)建程序入口類Application.java

      packagecom.xuejia.ad;

      importorg.springframework.boot.SpringApplication;

      importorg.springframework.boot.autoconfigure.SpringBootApplication;

      /**

      *@authorkehaojian

      *@date2017-12-28 8:33

      *@since1.0.0

      */

      @SpringBootApplication

      public classApplication {

         public static voidmain(String[] args) {

             SpringApplication.run(Application.class, args);

         }

      }

      spring-boot之一:簡單入門

      4.創(chuàng)建一個controller類

      packagecom.xuejia.ad.controller;

      importorg.springframework.web.bind.annotation.RequestMapping;

      importorg.springframework.web.bind.annotation.RestController;

      /**

      *@authorkehaojian

      *@date2017-12-28 8:35

      *@since1.0.0

      */

      @RestController

      public classStartDemoController {

         @RequestMapping("/")

         String home(){

             return"hello";

         }

      }

      5.配置application.yml

      server:

       port:8888

       tomcat:

         uri-encoding:utf-8

      spring:

       redis:

         host:localhost

         port:6379

         pool:

           max-active:8

           min-idle:0

           max-idle:8

           max-wait:-1

      spring-boot之一:簡單入門spring-boot之一:簡單入門

      5.運(yùn)行Application的main方法

      spring-boot之一:簡單入門spring-boot之一:簡單入門

      6.在瀏覽器中輸入http://localhost:8888/

      spring-boot之一:簡單入門spring-boot之一:簡單入門

      7.在pom.xml增加spring-boot-starter-redis以及spring-boot-starter-test依賴包

         org.springframework.boot

         spring-boot-starter-test

         org.springframework.boot

         spring-boot-starter-redis

      8.創(chuàng)建redis配置類RedisConfig

      packagecom.xuejia.ad.config;

      importcom.fasterxml.jackson.annotation.JsonAutoDetect;

      importcom.fasterxml.jackson.annotation.PropertyAccessor;

      importcom.fasterxml.jackson.databind.ObjectMapper;

      importorg.slf4j.Logger;

      importorg.slf4j.LoggerFactory;

      importorg.springframework.boot.context.properties.ConfigurationProperties;

      importorg.springframework.context.annotation.Bean;

      importorg.springframework.context.annotation.Configuration;

      importorg.springframework.data.redis.connection.RedisConnectionFactory;

      importorg.springframework.data.redis.connection.jedis.JedisConnectionFactory;

      importorg.springframework.data.redis.core.RedisTemplate;

      importorg.springframework.data.redis.core.StringRedisTemplate;

      importorg.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

      importredis.clients.jedis.JedisPoolConfig;

      /**

      *@authorkehaojian

      *@date2017-12-28 9:08

      *@since1.0.0

      */

      @Configuration

      @ConfigurationProperties(prefix="spring.redis")

      public classRedisConfig {

         private staticLoggerlogger= LoggerFactory.getLogger(RedisConfig.class);

         /*@Bean

         public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {

             StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory);

             Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);

             ObjectMapper objectMapper = new ObjectMapper();

             objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);

             objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

             jackson2JsonRedisSerializer.setObjectMapper(objectMapper);

             template.setValueSerializer(jackson2JsonRedisSerializer);

             template.afterPropertiesSet();

             return template;

         }

      */

         @Bean

         publicJedisPoolConfig getRedisConfig(){

             JedisPoolConfig config =newJedisPoolConfig();

             returnconfig;

         }

         @Bean

         publicJedisConnectionFactory getConnectionFactory(){

             JedisConnectionFactory factory =newJedisConnectionFactory();

             JedisPoolConfig config = getRedisConfig();

             factory.setPoolConfig(config);

             logger.info("JedisConnectionFactory bean init success.");

             returnfactory;

         }

         @Bean

         publicRedisTemplate getRedisTemplate(){

             RedisTemplate template =newStringRedisTemplate(getConnectionFactory());

             returntemplate;

         }

      }

      9.創(chuàng)建redis簡單工具類

      packagecom.xuejia.ad.common;

      importorg.springframework.beans.factory.annotation.Autowired;

      importorg.springframework.data.redis.core.RedisTemplate;

      importorg.springframework.stereotype.Repository;

      importjava.util.concurrent.TimeUnit;

      /**

      *@authorkehaojian

      *@date2017-12-28 9:04

      *@since1.0.0

      */

      @Repository

      public classRedisUtil {

         @Autowired

         privateRedisTemplateredisTemplate;

         public voidadd(String key, String value, Long time){

             redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);

         }

         publicString get(String key) {

             returnredisTemplate.opsForValue().get(key);

         }

         public voiddelete(String key) {

             redisTemplate.opsForValue().getOperations().delete(key);

         }

      }

      10.在test目錄下創(chuàng)建一個測試類RedisTest

      importcom.xuejia.ad.common.RedisUtil;

      importcom.xuejia.ad.config.RedisConfig;

      importorg.junit.Before;

      importorg.junit.Test;

      importorg.junit.runner.RunWith;

      importorg.springframework.beans.factory.annotation.Autowired;

      importorg.springframework.test.context.ContextConfiguration;

      importorg.springframework.test.context.junit4.SpringJUnit4Cla***unner;

      /**

      *@authorkehaojian

      *@date2017-12-28 9:17

      *@since1.0.0

      */

      @RunWith(SpringJUnit4Cla***unner.class)

      @ContextConfiguration(classes = {RedisConfig.class, RedisUtil.class})

      public classRedisTest {

         @Autowired

         privateRedisUtilredisUtil;

         @Before

         public voidtestbefore() {

             redisUtil.add("kehaojian","helloworld",100L);

         }

         @Test

         public voidtestRedis()throwsInterruptedException {

             inttotal =20;

             for(inti =0; i <20; i++){

                 System.out.println(redisUtil.get("kehaojian"));

                 Thread.sleep(5000);

             }

         }

      }

      11.運(yùn)行測試類,結(jié)果如下

      18:57:26.975 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Opening RedisConnection

      18:57:26.975 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Closing Redis Connection

      helloworld

      18:57:31.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Opening RedisConnection

      18:57:31.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Closing Redis Connection

      helloworld

      18:57:36.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Opening RedisConnection

      18:57:36.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Closing Redis Connection

      helloworld

      18:57:41.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Opening RedisConnection

      18:57:41.976 [main] DEBUG org.springframework.data.redis.core.RedisConnectionUtils - Closing Redis Connection

      12.打包,在pom.xml增加打包插件配置

         

             

                 org.springframework.boot

                 spring-boot-maven-plugin

                 

                     

                         

                             repackage

                         

                     

                 

             

         

      13.執(zhí)行package操作

      spring-boot之一:簡單入門spring-boot之一:簡單入門


      網(wǎng)站標(biāo)題:spring-boot之一:簡單入門
      文章源于:http://www.ef60e0e.cn/article/jeseod.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        玛沁县| 精河县| 泰顺县| 河间市| 永福县| 孝义市| 迁安市| 四平市| 洪洞县| 城市| 武义县| 东方市| 平阳县| 犍为县| 东宁县| 九寨沟县| 大丰市| 安塞县| 南部县| 楚雄市| 法库县| 滨州市| 鄢陵县| 江门市| 宁陵县| 无为县| 甘谷县| 广元市| 济南市| 景德镇市| 宁波市| 剑河县| 芜湖县| 宜都市| 纳雍县| 连云港市| 平武县| 新和县| 房产| 巴林左旗| 吉林市|