SpringBoot 集成 redis
1.添加redis依赖 : spring-boot-starter-data-redis
2.注入RedisTemplate
3.配置文件中配置 spring.redis.host spring.redis.password spring.redis.port
SpringBoot集成mongodb
1.添加mongodb的依赖:spring-boot-starter-data-monogodb
2.注入MongoOperations,通过MongoOperations操作数据库
或者定义接口实现MongoRepository, 并注解@Repository.同时实体类上注解@Document 和 @Id
3.service注入MongoRepository的实现类
4.配置文件中配置 : spring.data.mongodb.host spring.data.mongodb.database
SpringBoot集成Beetl
添加beetl依赖 : beetl-framework-starter
配置bean
方式1 配置BeetlTemplateCustomize
@Bean
public BeetlTemplateCustomize beetlTemplateCustomize(){
return new BeetlTemplateCustomize(){
public void customize(GroupTemplate groupTemplate){
}
};
}
方式2 配置BeetlGroupUtilConfiguration 与 BeetlSpringViewResolver
@Bean(initMethod = "init", name = "beetlConfig")
public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration() {
BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
ResourcePatternResolver patternResolver = ResourcePatternUtils
.getResourcePatternResolver(new DefaultResourceLoader());
try {
WebAppResourceLoader cploder = new WebAppResourceLoader(patternResolver.getResource("/templates").getFile().getPath());
beetlGroupUtilConfiguration.setResourceLoader(cploder);
return beetlGroupUtilConfiguration;
} catch (Exception e) {
throw new RuntimeException(e);
}
return beetlGroupUtilConfiguration;
}
@Bean(name = "beetlViewResolver")
public BeetlSpringViewResolver getBeetlSpringViewResolver(
@Qualifier("beetlConfig") BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
beetlSpringViewResolver.setSuffix(".btl");
beetlSpringViewResolver.setOrder(0);
beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration);
return beetlSpringViewResolver;
}