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, 如何学习比较困惑, 思前想后最后决定从文档来学习, 以下为学习中的参考资料: ...
随机推荐
- 【转】视频H5 video最佳实践
原文地址:https://github.com/gnipbao/iblog/issues/11 随着 4G 的普遍以及 WiFi 的广泛使用,手机上的网速已经足够稳定和高速,以视频为主的 HTML5 ...
- DRUID连接池配置详情
DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针 ...
- Java开发笔记(八十九)缓存字节I/O流
文件输出流FileOutputStream跟FileWriter同样有个毛病,每次调用write方法都会直接写到磁盘,使得频繁的写操作性能极其低下.正如FileWriter搭上了缓存兄弟Buffere ...
- HTML 练习拖动面板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- DNS服务详解
DNS服务 目录: 一.DNS原理 二.DNS服务的安装与配置 三.DNS信息收集 一.DNS原理 1.hosts文件与DNS服务器 1.1hosts文件 目录:C:\WINDOWS\system32 ...
- PyQt5 api 帮助文档
学习PyQt5的帮助文档是通过,使用help(PyQt5 class)的方式在console端输出帮助内容,常用的方法和属性查找起来不是很方便,现在放在网上以方便大家使用. QWidget Qt QM ...
- MySQL 文章目录
MySQL系列: MySQL CREATE TABLE语法 MySQL 复制表结构 MySQL 对比数据库表结构 MySQL 处理插入过程中的主键唯一键重复值办法 MySQL 启动原理剖析 MySQL ...
- Java EE中的容器和注入分析,历史与未来
Java EE中的容器和注入分析,历史与未来 java中的容器 java中的注入 容器和注入的历史和展望 一.java中的容器 java EE中的注入,使我们定义的对象能够获取对资源和其他依赖项的引用 ...
- 一文让你明白Redis主从同步
今天想和大家分享有关 Redis 主从同步(也称「复制」)的内容. 我们知道,当有多台 Redis 服务器时,肯定就有一台主服务器和多台从服务器.一般来说,主服务器进行写操作,从服务器进行读操作. 那 ...
- Python编程Day1——计算机组成与操作系统
一..计算机基础 二.编程与编程的目的 1.什么是语言? 一种事物与另外一种事物沟通的介质 编程语言是程序员与计算机沟通的介质 2.什么是编程? 程序员把自己想要让计算机做的事用编程语言表达出来,编程 ...