Spring

SpringBoot入门(一)——开箱即用

六月ゝ 毕业季﹏ 提交于 2021-02-11 18:55:55
本文来自 网易云社区 Spring Boot是什么 从根本上来讲Spring Boot就是一些库的集合,是一个基于“约定优于配置”的原则,快速搭建应用的框架。本质上依然Spring,在这之上帮我们省去了很多样板化的配置,使得我们能够更专注于应用程序功能的开发。 Spring Boot精要 SpringBoot将很多魔法带入了Spring应用程序的开发之中,其中最重要的是以下四个核心 自动配置:针对常见的应用功能,SpringBoot自动提供相关的配置,减少用于样板化配置的时间 起步依赖:指定基于功能的依赖,用更大粒度的依赖来降低依赖的复杂度 命令行界面:这是SpringBoot的可选特性,借此你只需要写代码就能完成完整的应用程序,无需传统项目构建 Actuator:让你能够深入运行中的SpringBoot应用程序一探究竟 从Spring开始 为了体现SpringBoot的优势,我们先来看看如果使用Spring开发一个简单的Hello World Web应用程序,我们需要做的事情: 一个项目结构,其中有一个包含必要依赖的Maven或者Gradle构件文件,最起码要有Spring MVC和Servlet API这些依赖 一个web.xml文件(或者一个WebApplicationInitializer实现),其中声明了Spring的DispatcherServlet

IntelliJ does't have @NotBlank

别等时光非礼了梦想. 提交于 2021-02-11 18:19:24
问题 So im running my program and I need to setup @NotNull from import javaz.validation.constraints.NotBlank; All there is @NonNull private final String firstName; and import org.springframework.lang.NonNull; How do I install @NotNull or is @NonNull the same thing? 回答1: This should answer your question. Short answer: there is a subtle difference, but it all depends on what you want, so you either need to read the post I've linked above or tell us more information. 来源: https://stackoverflow.com

IntelliJ does't have @NotBlank

ⅰ亾dé卋堺 提交于 2021-02-11 18:19:09
问题 So im running my program and I need to setup @NotNull from import javaz.validation.constraints.NotBlank; All there is @NonNull private final String firstName; and import org.springframework.lang.NonNull; How do I install @NotNull or is @NonNull the same thing? 回答1: This should answer your question. Short answer: there is a subtle difference, but it all depends on what you want, so you either need to read the post I've linked above or tell us more information. 来源: https://stackoverflow.com

Timestamp converter not working in Spring Data Rest with Spanner

て烟熏妆下的殇ゞ 提交于 2021-02-11 18:18:37
问题 I'm trying to convert the input timestamp which will be in the string format to cloud timestamp with the help of a Spring Data Rest custom converter which is not working. Need an help on the same in understanding why custom converters are not invoked. Input: http://localhost:8080/apipromocentral/promotions RequestBody : {"startDateTime": "2019-11-07 15:53:00"} POJO: @ApiModel @Data @AllArgsConstructor @Table(name = "PROMOTIONS") public class Promotion { /** * promotion id */ @ApiModelProperty

Timestamp converter not working in Spring Data Rest with Spanner

空扰寡人 提交于 2021-02-11 18:17:06
问题 I'm trying to convert the input timestamp which will be in the string format to cloud timestamp with the help of a Spring Data Rest custom converter which is not working. Need an help on the same in understanding why custom converters are not invoked. Input: http://localhost:8080/apipromocentral/promotions RequestBody : {"startDateTime": "2019-11-07 15:53:00"} POJO: @ApiModel @Data @AllArgsConstructor @Table(name = "PROMOTIONS") public class Promotion { /** * promotion id */ @ApiModelProperty

mvn test fails but running the test from IntelliJ IDEA pass

随声附和 提交于 2021-02-11 18:10:47
问题 I have this a test that I run under @RunWith(SpringRunner.class) @SpringBootTest @Test public void testFind() throws IOException { Review<Hostel> hostelByComplaintId = hostelService.findByComplaintId(complaintId).orElse(null); assertThat(hostelByComplaintId).isNotNull(); } when I run the test from the command line mvn test I got this error Failed tests: Expecting actual not to be null but when I run it from IntelliJ IDEA, the test does not fail 回答1: You can just write complete command if

mvn test fails but running the test from IntelliJ IDEA pass

て烟熏妆下的殇ゞ 提交于 2021-02-11 18:10:39
问题 I have this a test that I run under @RunWith(SpringRunner.class) @SpringBootTest @Test public void testFind() throws IOException { Review<Hostel> hostelByComplaintId = hostelService.findByComplaintId(complaintId).orElse(null); assertThat(hostelByComplaintId).isNotNull(); } when I run the test from the command line mvn test I got this error Failed tests: Expecting actual not to be null but when I run it from IntelliJ IDEA, the test does not fail 回答1: You can just write complete command if

Spring Boot 整合Druid数据源(一)

不羁的心 提交于 2021-02-11 18:10:02
Druid是阿里巴巴的一个开源的JDBC组件,该组件由数据库连接池、插件框架和SQL解析器组成,主要功能如下: 1.DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系。 2.DruidDataSource 高效可管理的数据库连接池。 3.SQLParser解析器兼容所有的JDBC数据库,如:Mysql,Oracle、SQL Server数据库。 同时它结合了C3P0、DBCP、PROXOOL等DB池的优点,加入了日志监控,在稳定性、可扩展性和性能方便具有明显的优势,可以通过监控功能分析数据库连接和SQL的执行情况。 Spring Boot 整合Druid有两种方式: 第一种:druid依赖包; 第二种:druid-spring-boot-starter依赖包,已分享: Spring Boot 整合Druid数据源(二) ; 这里使用的是第一种方式,第一种方式需要使用@Configuration将Druid数据源注册到IOC容器中,需要配置管理后台的Servlet和配置web监控的过滤器,这里使用是2.0.2.RELEASE 版本. 1.引入Druid依赖包 打开pom.xml文件加入,如下代码: < dependency >    < groupId > com.alibaba </ groupId >    < artifactId >

JAVA面试题

放肆的年华 提交于 2021-02-11 18:06:14
1.HashMap和Hashtable的区别 2.StringBuilder内部实现机制 3.SpringMVC和Struts2的区别 4.Spring事务的管理 5.Hibernate与MyBatis的比较 6.GC算法有哪些 7.垃圾回收器有哪些 8.如何调优JVM 9.Java 中堆和栈有什么区别? 10.缓存命中率的计算 11.Memcache与Redis的区别 12.如何实现Redis的分片 13.zookeeper的用途 14.dubbo的用途以及优点 15.HashMap和HashTable存储原理 16.说说堆的年轻代和老年代 17.HTTP协议,GET和POST 的区别 18.栈溢出的原因有哪些 17.String、StringBuffer与StringBuilder之间区别 20.堆内存和栈内存的区别 21.讲讲分布式唯一ID 22.对象克隆和实现方式 23.集群环境中,session如何实现共享 24.short s1 = 1; s1 = s1 + 1;有错吗?short s1 = 1; s1 += 1;有错吗? 25.如何实现对象克隆? 26.唤醒一个阻塞的线程 27.说说NIO和IO的区别 28.Java中的NIO,BIO,AIO分别是什么? 29.什么是幂等性 30.终止线程有几种方式?终止线程标记变量为什么是 valotile 类型? 31

get application domain + port and path programmatically in spring?

百般思念 提交于 2021-02-11 17:51:32
问题 My website calls a rest service which is also on the same application. I don't want to change the domain of the rest address if it's hosted on a different domain name and/or port. I want to get the domain, port and application path programmatically. If we are accessing the website like http://example.com/article1 then I should get http://example.com or if our address is like below http://example.com:8080/ArticleSite/article1 then I want to get http://example.com:8080/ArticleSite How can this