发表于: 2017-11-20 23:27:00
2 655
今日完成:
1)学习springboot(这东西一直想学来着,因为这东西的出现就是简化spring配置的。而且spring也学的差不多了,既然有了更简单的东西,为什么不去尝试呢。另外,,,,现在这东西也很火,,,建议师兄有时间也瞅一下)
首先:什么是springboot
看我的博客:http://blog.csdn.net/zq17865815296/article/details/78578154
2)springboot的使用(基本使用):
先说一下几个Springboot常用的注解:
@Configuration 放在类上,相当于一个xml文件
@Bean 放在方法上,相当于一个bean
@PropertySource(values={classpath},ignorceResourceFound=true):这样会忽略没有扫描到的文件
@ComponentScan:默认扫描当前类以及当前类的子类
@EnableAutoConfiguration:这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。
@SpringBootApplication(它会自动推断是什么项目,并导入想入配置);配置了它就相当于配置了@Configuration @EnableAutoConfiguration,
如果不想一些自动配置,使用exclude={****.class}
springboot启动一个web项目:
首先需要的依赖:
<!--start包含核心的maven依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<!--排除它内置的日志,因为想使用log4j-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!--使用log4j-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<!--引入一个web项目需要的配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
这些maven配置会自动引入需要的maven依赖,启动一个web项目
@RestController
@SpringBootApplication(exclude = {RabbitAutoConfiguration.class})
public class BoottestApplication {
@Autowired
private UserService userService;
private static Logger logger= Logger.getLogger(BoottestApplication.class);
@RequestMapping("/hello")
public String hello(){
return "哈喽,world";
}
@RequestMapping
public List<User> findAll(){
return userService.findAll();
}
public static void main(String[] args) {
SpringApplication.run(BoottestApplication.class, args);
logger.error("哈嘍,沃德");
}
}
除此之外,Springboot提倡的是javaconfig。所以,今天顺带的把javaconfig学习了一下。还有配置服务器端口,配置拦截器,与mybatis整合,具体太多了。明天再写一篇博客记录一下
3)回到任务
在Linux下安装memcached,今天安装出现一个问题,硬件时间与系统时间不一致,导致安装失败。这里就说一下两条命令:
date:获取系统时间
hwclock:获取硬件时间
如果系统时间晚于需要安装的文件的时间,会出现安装失败。解决办法:先将系统时间与硬件时间同步
hwclock --systohc :硬件时间与系统时间一致(系统为准)
hwclock --hctosys:系统时间与硬件时间一致(硬件为准)
当与网络时间不一致的时候,可以使用: ntpdate -u ntp.api.bz进行同步
今日疑问:
无
明日计划:
做完负载均衡服务器的测压,争取交上任务六~~
评论