springboot模块
1.web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
server.context-path=/
server.port=80
server.session.timeout=60
server.tomcat.max-threads=800
server.tomcat.uri-encoding=UTF-8
@ComponentScan(basePackages="com.atguigu")
2.字符编码
spring.http.encoding.charset=UTF-8
spring.http.encoding.force=true
3.freemarker
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
spring.freemarker.allow-request-override=false
spring.freemarker.allow-session-override=false
spring.freemarker.cache=true
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.enabled=true
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=true
spring.freemarker.prefer-file-system-access=false
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.settings.template_update_delay=0
spring.freemarker.settings.default_encoding=UTF-8
spring.freemarker.settings.classic_compatible=true
spring.freemarker.order=1
4.集成Nginx
server.address=127.0.0.1
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.port-header=X-Forwarded-Port
server.use-forward-headers=true
5.redis
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
spring.session.store-type=redis
spring.redis.database=1
spring.redis.host=127.0.0.1
spring.redis.password=123123
spring.redis.port=6379
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
spring.redis.timeout=60000
@Configuration
@EnableRedisHttpSession
public class RedisSessionConfig {
}
设置Redis Session共享后,如果向Session中保存数据,需要让数据对象实现可序列化接口java.io.Serializable
6.mysql,pool,mybatis
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
spring:
datasource:
name: mydb
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://127.0.0.1:3306/atcrowdfunding
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapperLocations: classpath*:mybatis/mapper-*.xml
typeAliasesPackage: com.atguigu.**.bean
@MapperScan("com.atguigu.**.dao")
@EnableTransactionManagement
@Transactional(readOnly=true)
public interface MemberDao {
@Select("select * from t_member where id = #{id}")
public Member queryById(Integer id);
@Insert("insert into t_member (loginacct) values (#{loginacct})")
public int insertMember(Member member);
}
7.热部署
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional><!-- 这个需要为 true 热部署才有效-->
</dependency>
8.打jar包 :数据库文件位置不对.将src/main/resources下的文件复制到src/main/java目录下,再打jar包即可.
打war包:需要将springboot tomcat模块设成provided
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
9
9.1注册中心
建项目时勾选Eureka Server
在类前增加注解@EnableEurekaServer
在application.properties文件中,增加配置信息
...
spring.application.name=eureka-server
server.port=1001
eureka.instance.hostname=127.0.0.1
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
...
9.2服务端
建项目时勾选Eureka Discovery
在类前增加注解@EnableDiscoveryClient
在application.properties文件中,增加配置信息
spring.application.name=eureka-member-service
server.port=2001
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:1001/eureka/
9.3客户端
建项目时勾选Eureka Discovery和Feign
在类前增加注解@EnableDiscoveryClient, @EnableFeignClients
在application.properties文件中,增加配置信息
spring.application.name=eureka-member-client
server.port=80
eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/
@FeignClient("eureka-member-service")
public interface MemberClient {
@GetMapping("/test")
String test(); //与服务的方法返回类型一致
}
@FeignClient("eureka-member-service")中的字符串内容应该和会员服务在注册中心注册的名称相同eureka-member-service
springboot模块的更多相关文章
- 搭建maven聚合工程包含springboot模块
一.新建一个maven项目 二.删除src 打开pom.xml 补充标签 <packaging>pom</packaging> 新建 <module>brr- ...
- activiti的springboot模块
目标: springboot 下 使用activiti,搭建微服务,并且使用自己的用户与组 版本 activiti version 5.22.0spring boot version 1.5.1 主要 ...
- idea 创建 springboot 模块报错-解决
1.报错截图 2.解决 把 https://start.spring.io 换成 阿里镜像的即可 https://start.aliyun.com/
- IDEA+Maven+多个Module模块(创建多模块SpringBoot整合项目)
最近在学习springboot,先从创建项目开始,一般项目都是一个项目下会有多个模块,这里先创建一个最简单的实例,一个项目下有一个springboot模块项目提供web服务,引用另一个java项目(相 ...
- 如何分析SpringBoot源码模块及结构?--SpringBoot源码(二)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 前言 本篇接 如何搭建自己的SpringBoot源码调试环境?--SpringBoot源码(一). 前面搭建好了自己本地的S ...
- 带着萌新看springboot源码13(手写一个自己的starter)
springboot的最强大的就是那些xxxAutoconfiguration,但是这些xxxAutoConfiguration又依赖那些starter,只有导入了这些场景启动器(starter),我 ...
- IDEA创建多个模块MavenSpringBoot项目
最近在学习springboot,先从创建项目开始,一般项目都是一个项目下会有多个模块,这里先创建一个最简单的实例,一个项目下有一个springboot模块项目提供web服务,引用另一个java项目(相 ...
- SpringBoot编写自定义Starter
根据SpringBoot的Starter编写规则,需要编写xxxStarter依赖xxxAutoConfigurer,xxxStarter是一个空的jar,仅提供辅助性的依赖管理,引入其他类库 1.建 ...
- SpringBoot(一)初遇
环境: IDEA 2018.1.3 , jdk 1.8 , maven 3.3.9 零 第一次接触springboot, 如何学习比较困惑, 思前想后最后决定从文档来学习, 以下为学习中的参考资料: ...
随机推荐
- .NET(C#、VB)APP开发——Smobiler平台控件介绍:SignatureButton控件
SignatureButton控件 一. 样式一 我们要实现上图中的效果,需要如下的操作: 从工具栏上的"Smobiler Components"拖动一个Sign ...
- maven 依赖中scope标签的配置范围详解
在创建Maven项目时,需要在pom.xml 文件中添加相应的依赖,其中有一个scope标签,该标签是设置该依赖范围 (maven项目包含三种classpath{编译classpath,测试class ...
- Http通讯Util
目录 HttpUtil类 HttpUtil类 import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...
- 如何给自己的app添加分享到有道云笔记这样的功能
文章同步自http://javaexception.com/archives/34 如何给自己的app添加分享到有道云笔记这样的功能 问题: 在之前的一个开源笔记类项目Leanote中,有个用户反馈想 ...
- 工程实践:给函数取一个"好"的名字
工程实践:给函数取一个"好"的名字 早在2013年,国外有个程序员做了一个有意思的投票统计(原始链接请见:<程序员:你认为最难做的事情是什么?>),该投票是让程序员从以 ...
- Git:一、简介&安装Git 2.20.1
0.Git官网 1.简介 一个分布式版本控制系统. 作用:自动记录每次文件的改动,还可以让同伴协作编辑. 分布式与集中式相比优点在于:版本库在每个人自己电脑上,不需要一直在网上,也不用担心某一个数据库 ...
- Java辅助类持续汇总~
/** * 01 * 描述:List<String>集合去除重复数据 * [时间 2019年3月5日下午3:54:09 作者 陶攀峰] */ public static List<S ...
- CenOS_命令帮助
1.帮助 1.1man 基本语法: man[命令或配置文件](功能描述:获得帮助信息) 如:man ll 1.2help 基本语法: help 命令 (功能描述:获得 shell 内置命令的帮助信息) ...
- Sql Server 本地(客户端)连接服务器端操作
网有很多相关内容,我在此做记录和总结 1.主要是sql server 配置管理工具的配置 在此参考 https://www.cnblogs.com/yougmi/p/4616273.html(再次感谢 ...
- Cesium3DTileset示例
3D Tiles是Cesium中很核心的一部分,尤其是用来实现大范围的模型场景数据的加载应用. 三维倾斜模型.人工建模.BIM模型等等,都可以转换成3D Tiles,进而为我们所用. 从Cesium1 ...