1. STS插件最好是要安装的.
2. 对应的Decompiler插件也是要安装的. 3. 如果遇到maven工程因为找不到包问题的, 在确认pom.xml 文件没有问题的情况下, 右键项目-Maven-Update Project 然后点击OK,更新一下工程, 还不行的 点击 Force Update of Snapshots/Releases 还不行的 删除.m2 Maven下载目录下的本地仓库所有文件,重新更新下载一遍 还不行的 在报错的Markers页签 右键删除报错信息 然后重新运行Spring Cloud 4.Spring-cloud 项目加入eureka后, restcontroller 默认返回的是xml格式,需要自定义一个配置类1 @Configuration 2 public class WebMvcConfig extends WebMvcConfigurerAdapter { 3 4 //解决spring-cloud 加载eureka后, restcontroller 默认返回xml格式 5 @Override 6 public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 7 configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.APPLICATION_JSON); 8 super.configureContentNegotiation(configurer); 9 }10 }
5. 如果需要在项目一启动,就执行某些代码,可以增加如下的监听器代码
1 @Component 2 public class OnStartListener implements ApplicationListener{ 3 4 @Override 5 public void onApplicationEvent(ContextRefreshedEvent event) { 6 System.out.println(event.getApplicationContext().getParent()); 7 System.out.println("on start: " + System.currentTimeMillis()); 8 } 9 10 }
6.启动事务时,要在启动类加入一些注解
1 /** 2 * 启动类 3 * @author wunaozai 4 * MapperScan : 扫描的是mapper.xml中namespace指向的包位置 5 * EnableTransactionManagement : 加入事务 6 * 加入@Transaction 事务处理后, spring 会启用动态代理方式, 7 * 所以在EnableTransactionManagement 要增加proxyTargetClass 8 */ 9 @EnableEurekaClient10 @SpringBootApplication11 @EnableTransactionManagement(proxyTargetClass=true)12 @MapperScan("com.wunaozai.xxx.center.mapper")13 public class ServiceDeveloperCenterApplication {14 15 public static void main(String[] args) {16 SpringApplication.run(ServiceDeveloperCenterApplication.class, args);17 }18 }
7.项目中各个文件夹(包名)都最好按照默认的约定的来,不要自己乱改.
8.一份简单的application.properties
1 spring.application.name=service-developer-center 2 3 #server 4 server.port=9200 5 server.session.timeout=360000 6 server.session.cookie.name=IOT 7 8 #eureka 9 eureka.client.serviceUrl.defaultZone=http://172.16.23.203:9000/eureka/10 eureka.instance.prefer-ip-address=true11 eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}12 13 #logging14 logging.path=log15 logging.level.com.favorites=INFO16 logging.level.org.springframework.web=INFO17 18 #datasource19 spring.datasource.url=jdbc:postgresql://172.16.23.202:5432/service_developer_center20 spring.datasource.username=postgres21 spring.datasource.password=22 spring.datasource.driverClassName=org.postgresql.Driver23 24 #mybatis25 mybatis.type-aliases-package=com.wunaozai.xxx.center.model26 mybatis.mapper-locations=classpath:com/wunaozai/xxx/center/mapper/*.xml27 28 #pagehelper29 pagehelper.helperDialect=postgresql30 pagehelper.reasonable=true31 pagehelper.supportMethodsArguments=true32 pagehelper.returnPageInfo=check33 34 #redis35 spring.redis.database=036 spring.redis.host=172.16.20.22937 spring.redis.port=637938 spring.redis.password=39 spring.redis.timeout=040 spring.redis.pool.max-active=841 spring.redis.pool.max-wait=-142 spring.redis.pool.max-idle=843 spring.redis.pool.min-idle=044 spring.cache.type=Redis45 46 #thymeleaf47 spring.thymeleaf.mode=HTML548 spring.thymeleaf.encoding=UTF-849 spring.thymeleaf.content-type=text/html50 spring.thymeleaf.cache=false51 52 #upload max file size53 spring.http.multipart.maxFileSize=25Mb54 spring.http.multipart.maxRequestSize=50Mb55 56 #email config57 spring.mail.host=192.168.8.20858 spring.mail.username=xxx@wunaozai.com59 spring.mail.password=60 srping.mail.default-encoding=UTF-8
9.一份简单的 pom.xml
1 24 4.0.0 5 6com.wunaozai.center 7service-developer-center 80.0.1 9jar 10 11service-developer-center 12XXX开发者中心 13 1415 20 21org.springframework.boot 16spring-boot-starter-parent 171.5.9.RELEASE 1819 22 27 28UTF-8 23UTF-8 241.8 25Edgware.SR1 2629 99 10030 33org.springframework.cloud 31spring-cloud-starter-eureka-server 3234 37org.springframework.boot 35spring-boot-starter-web 3638 41org.postgresql 39postgresql 4042 46 47org.mybatis.spring.boot 43mybatis-spring-boot-starter 441.3.1 4548 52com.github.pagehelper 49pagehelper-spring-boot-starter 501.2.3 5153 56 57org.springframework.boot 54spring-boot-starter-data-redis 5558 61org.springframework.session 59spring-session-data-redis 6062 65 66org.springframework.boot 63spring-boot-starter-thymeleaf 6467 71 72com.aliyun.oss 68aliyun-sdk-oss 693.0.0 7073 77 78commons-io 74commons-io 752.6 7679 83commons-fileupload 80commons-fileupload 811.3.3 8284 87 88org.springframework.boot 85spring-boot-starter-mail 8689 93org.springframework.boot 90spring-boot-devtools 91runtime 9294 98org.springframework.boot 95spring-boot-starter-test 96test 97101 111 112102 110103 109org.springframework.cloud 104spring-cloud-dependencies 105${spring-cloud.version} 106pom 107import 108113 120 121 122114 119115 118org.springframework.boot 116spring-boot-maven-plugin 117