一,准备工作,建立spring-boot-sample-redis工程
1、http://start.spring.io/
A、Artifact中输入spring-boot-sample-redis
B、勾选Web下的web
C、勾选NOSQL下的Redis
2、Eclips中导入工程spring-boot-sample-redis
A、解压快捷工程spring-boot-sample-redis到某文件夹
B、eclips中file->import->Import Existing Maven Projects-->Select Maven projects-->finish导入工程
3、工程导入之后,文件结构如下图
4、在包com.example下建立web文件夹
5、便于测试,引入spring-boot-sample-helloworld的HelloController及配置文件logback.xml
HelloController代码为
package com.example.web;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
protected static Logger logger=LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String helloworld(){
logger.debug("访问hello");
return "Hello world!";
}
@RequestMapping("/hello/{name}")
public String helloName(@PathVariable String name){
logger.debug("访问helloName,Name={}",name);
return "Hello "+name;
}
}
logback.xml配置为
<configuration>
<!-- %m输出的信息,%p日志