diff --git a/springboottest/springboottest7/.gitignore b/springboottest/springboottest7/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/springboottest/springboottest7/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/springboottest/springboottest7/pom.xml b/springboottest/springboottest7/pom.xml new file mode 100644 index 0000000..8bf2eac --- /dev/null +++ b/springboottest/springboottest7/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + com.jsoft.springboottest + springboottest1 + 0.0.1-SNAPSHOT + jar + + springboottest1 + http://maven.apache.org + + + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-parent + 1.4.7.RELEASE + + + + + junit + junit + test + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-devtools + true + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.springframework.session + spring-session-data-redis + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/App.java b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/App.java new file mode 100644 index 0000000..10a243b --- /dev/null +++ b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/App.java @@ -0,0 +1,17 @@ +package com.jsoft.springboottest.springboottest1; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Hello world! + * + */ +@SpringBootApplication +public class App +{ + public static void main( String[] args ) + { + SpringApplication.run(App.class, args); + } +} diff --git a/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/SessionConfig.java b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/SessionConfig.java new file mode 100644 index 0000000..53af736 --- /dev/null +++ b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/SessionConfig.java @@ -0,0 +1,9 @@ +package com.jsoft.springboottest.springboottest1; + +import org.springframework.context.annotation.Configuration; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@Configuration +@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60 * 60 * 24) +public class SessionConfig { +} diff --git a/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/controller/TestController.java b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/controller/TestController.java new file mode 100644 index 0000000..3f599c8 --- /dev/null +++ b/springboottest/springboottest7/src/main/java/com/jsoft/springboottest/springboottest1/controller/TestController.java @@ -0,0 +1,48 @@ +package com.jsoft.springboottest.springboottest1.controller; + +import java.util.UUID; + +import javax.servlet.http.HttpSession; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + private static final Logger logger = LoggerFactory.getLogger(TestController.class); + + @Autowired + RedisTemplate redisTemplate; + + @Autowired + StringRedisTemplate stringRedisTemplate; + + @RequestMapping("/set") + public void set() { + redisTemplate.opsForValue().set("test", "4321"); + } + + @RequestMapping("/show") + public String show(){ + + logger.info(redisTemplate.opsForValue().get("test").toString()); + return "Hello World"; + } + + @RequestMapping("/uid") + public String uid(HttpSession session) { + UUID uid = (UUID) session.getAttribute("uid"); + if (uid == null) { + uid = UUID.randomUUID(); + } + session.setAttribute("uid", uid); + return session.getId(); + } +} diff --git a/springboottest/springboottest7/src/main/resources/application.properties b/springboottest/springboottest7/src/main/resources/application.properties new file mode 100644 index 0000000..11c32cf --- /dev/null +++ b/springboottest/springboottest7/src/main/resources/application.properties @@ -0,0 +1,31 @@ +# REDIS\uff08RedisProperties\uff09 +# \uff08\u666e\u901a\u96c6\u7fa4\uff0c\u4e0d\u4f7f\u7528\u5219\u4e0d\u7528\u5f00\u542f\uff09\u5728\u7fa4\u96c6\u4e2d\u6267\u884c\u547d\u4ee4\u65f6\u8981\u9075\u5faa\u7684\u6700\u5927\u91cd\u5b9a\u5411\u6570\u76ee\u3002 +# spring.redis.cluster.max-redirects= +# \uff08\u666e\u901a\u96c6\u7fa4\uff0c\u4e0d\u4f7f\u7528\u5219\u4e0d\u7528\u5f00\u542f\uff09\u4ee5\u9017\u53f7\u5206\u9694\u7684\u201c\u4e3b\u673a\uff1a\u7aef\u53e3\u201d\u5bf9\u5217\u8868\u8fdb\u884c\u5f15\u5bfc\u3002 +# spring.redis.cluster.nodes= +# \u8fde\u63a5\u5de5\u5382\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7d22\u5f15\u3002 +spring.redis.database=0 +# \u8fde\u63a5URL\uff0c\u5c06\u8986\u76d6\u4e3b\u673a\uff0c\u7aef\u53e3\u548c\u5bc6\u7801\uff08\u7528\u6237\u5c06\u88ab\u5ffd\u7565\uff09\uff0c\u4f8b\u5982\uff1aredis://user:password@example.com:6379 +spring.redis.url= +# Redis\u670d\u52a1\u5668\u4e3b\u673a\u3002 +spring.redis.host=localhost +# \u767b\u5f55redis\u670d\u52a1\u5668\u7684\u5bc6\u7801\u3002 +spring.redis.password= +# \u542f\u7528SSL\u652f\u6301\u3002 +spring.redis.ssl=false +# \u6c60\u5728\u7ed9\u5b9a\u65f6\u95f4\u53ef\u4ee5\u5206\u914d\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002\u4f7f\u7528\u8d1f\u503c\u65e0\u9650\u5236\u3002 +spring.redis.pool.max-active=8 +# \u6c60\u4e2d\u201c\u7a7a\u95f2\u201d\u8fde\u63a5\u7684\u6700\u5927\u6570\u91cf\u3002\u4f7f\u7528\u8d1f\u503c\u8868\u793a\u65e0\u9650\u6570\u91cf\u7684\u7a7a\u95f2\u8fde\u63a5\u3002 +spring.redis.pool.max-idle=8 +# \u8fde\u63a5\u5206\u914d\u5728\u6c60\u88ab\u8017\u5c3d\u65f6\u629b\u51fa\u5f02\u5e38\u4e4b\u524d\u5e94\u8be5\u963b\u585e\u7684\u6700\u957f\u65f6\u95f4\u91cf\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u3002\u4f7f\u7528\u8d1f\u503c\u53ef\u4ee5\u65e0\u9650\u671f\u5730\u963b\u6b62\u3002 +spring.redis.pool.max-wait=-1 +# \u76ee\u6807\u4e3a\u4fdd\u6301\u5728\u6c60\u4e2d\u7684\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u53ea\u6709\u5728\u6b63\u9762\u7684\u60c5\u51b5\u4e0b\u624d\u6709\u6548\u679c\u3002 +spring.redis.pool.min-idle=0 +# Redis\u670d\u52a1\u5668\u7aef\u53e3\u3002 +spring.redis.port=6379 +# \uff08\u54e8\u5175\u6a21\u5f0f\uff0c\u4e0d\u4f7f\u7528\u5219\u4e0d\u7528\u5f00\u542f\uff09Redis\u670d\u52a1\u5668\u7684\u540d\u79f0\u3002 +# spring.redis.sentinel.master= +# \uff08\u54e8\u5175\u6a21\u5f0f\uff0c\u4e0d\u4f7f\u7528\u5219\u4e0d\u7528\u5f00\u542f\uff09\u4e3b\u673a\uff1a\u7aef\u53e3\u5bf9\u7684\u9017\u53f7\u5206\u9694\u5217\u8868\u3002 +# spring.redis.sentinel.nodes= +# \u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u7684\u8fde\u63a5\u8d85\u65f6\u3002 +spring.redis.timeout=0 \ No newline at end of file diff --git a/springboottest/springboottest7/src/test/java/com/jsoft/springboottest/springboottest1/AppTest.java b/springboottest/springboottest7/src/test/java/com/jsoft/springboottest/springboottest1/AppTest.java new file mode 100644 index 0000000..d273591 --- /dev/null +++ b/springboottest/springboottest7/src/test/java/com/jsoft/springboottest/springboottest1/AppTest.java @@ -0,0 +1,38 @@ +package com.jsoft.springboottest.springboottest1; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}