随笔分类 - spring+mybatis
摘要:1、控制器级别@ExceptionHandler public class FooController{ //... @ExceptionHandler({ CustomException1.class, CustomException2.class }) public void handleExc
阅读全文
摘要:import java.math.BigDecimal; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; import javax.annotation.Reso
阅读全文
摘要:应用不用Spring MVC, 采用ErrorPageRegistrar 接口能直接映射errors。 1、概览 2、java代码 1)、MyAppServlet 2)、MyErrorPageRegistrar 3)、NotFoundServlet 4)、RuntimeExceptionServle
阅读全文
摘要:1、概览 2、在《springboot - 返回JSON error 从自定义的 ErrorController》基础上,做如下调整: 1)、新增Attribute类和Error类 2)、修改MyCustomErrorController类 3、执行 1)、http://localhost:8080
阅读全文
摘要:使用AbstractErrorController(是ErrorController的实现),返回json error。 1、概览 2、基于《springboot - 映射 /error 到自定义且实现了ErrorController的Controller》,仅修改MyCustomErrorCont
阅读全文
摘要:1、概览 基于《springboot - 映射 /error 到自定义且实现了ErrorController的Controller》改造,仅将MyCustomErrorController类修改如下: 执行: 在我们自定义的 ErrorController中使用ErrorAttributes,可代替
阅读全文
摘要:1、总览 2、代码 1)、pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </depend
阅读全文
摘要:1、总览 2、代码 1)、pom.xml 这里注意:springboot 2.2.0以后默认的freemarker文件后缀为:ftlh。本例用的是2.2.1,所以后缀为ftlh <dependencies> <dependency> <groupId>org.springframework.boot
阅读全文
摘要:1、总览 2、代码 1)、pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </depend
阅读全文
摘要:1、总览 2、代码 1)、pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </depend
阅读全文
摘要:1、总览 2、application.properties 3、controller 4、error.jsp 因为spring boot 提供了一个默认的mapping:/error,因此,我们起的错误jsp页面的文件名为error.jsp 5、执行 当执行http://localhost:8080
阅读全文
摘要:当访问不存在的页面时报错: 如何关闭它?有2种方法, 方法1: 方法2:在MyApplication上边的注解@SpringBootApplication中加入:exclude = ErrorMvcAutoConfiguration.class,即: 当访问不存在资源时, 方法1返回: 方法2返回:
阅读全文
摘要:1、 输出:from my bean, date: Fri Nov 15 14:16:37 GMT+08:00 2019 2、 输出:from MyBean myStringValue 3、 输出:from other bean 4、 输出:from MyBean: my string proper
阅读全文
摘要:1、MytestApplication 2、StartupOrder 输出日志: 13:57:38.764 DEBUG | Loading source class com.gomepay.MytestApplication13:57:38.813 DEBUG | Activated activeP
阅读全文
摘要:优先级: 使用于 示例1:by name 示例2:by type 只需修改ResourceTest.java中的代码: 将@Resource中的name=namedFile去掉,也能成功。因为,上例中File类型的对象只有nameFile,所以可以使用by type。 示例3:by qualifie
阅读全文
摘要:当一个接口,有多个实现类且均已注入到spring容器中了,使用时@AutoWired是byType的,而这些实现类类型都相同,此时就需要使用@Qualifier明确指定使用那个实现类。因此,@Qualifier是byName的。 1、基本 idea提示,必须添加@Qualifier,否则红线。 最后
阅读全文
摘要:在springboot中启用了@SpringBootApplication注解,就能启用spring内建注解。包含@AutoWired。 @AutoWired可标记到 属性 setter 构造器 FooFormatter 1、属性 2、setter 3、构造器 如果依赖的对象没有被注入,如 就会抛出
阅读全文
摘要:spring cloud包含的核心特性: Distributed/versioned configuration(分布式配置) Service registration and discovery(服务注册和发现) Routing(路由) Service-to-service calls(服务调用)
阅读全文
摘要:常用内建的Endpoints: 如果需要暴露Endpoints,需在application.properties或启动参数中,增加: 或者 示例: 1、在pom.xml中加入依赖 2、在application.properties中,加入 3、启动,日志发现 4、执行 输出: "java.runti
阅读全文
浙公网安备 33010602011771号