org.springframework.util.Assert

使用assert的好处就是比较简介,不用加try catch就可以附加一些预期的提示信息,方便定位问题

import org.springframework.util.Assert;

public class Demo {
    public static void main(String[] args) {
        String location = null;
        Assert.notNull(location, "Location must not be null");
        System.out.println("location = [" + location + "]");
    }
}

Output:

Exception in thread "main" java.lang.IllegalArgumentException: Location must not be null
	at org.springframework.util.Assert.notNull(Assert.java:115)
	at Demo.main(Demo.java:9)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

 

时间: 2024-09-05 22:58:52

org.springframework.util.Assert的相关文章

Spring Assert.notNull

  Exception in thread "main" java.lang.IllegalArgumentException: Source must not be null at org.springframework.util.Assert.notNull(Assert.java:115) at Test.getaVoid(Test.java:11) at Test.main(Test.java:6) at sun.reflect.NativeMethodAccessorImpl

spring security启动异常,求大神来指点下

问题描述 SSH想加上spring security,搞了几天都没搞出来,哪位大神来指点下  WEB.XML配置 <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation<

Spring Boot MyBatis 通用Mapper插件集成

看本文之前,请确保你已经在SpringBoot中集成MyBatis,并能正常使用. 如果没有,那么请先移步 http://blog.csdn.net/catoop/article/details/50553714 做了解后,再按本文步骤操作. 使用MyBatis在我们通过xml集中配置SQL,并通过创建接口Mapper文件来完成持久化DAO层(mybatis内部使用的是动态代理,所以我们不需要自己编写实现类). 然而在实际开发中,单表操作非常多,如果你也想像JPA.JDBC那样做一个所谓的Bas

hibernate-Maven test一个Web项目,报错,弄了一天没弄好,求高手解答

问题描述 Maven test一个Web项目,报错,弄了一天没弄好,求高手解答 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/Delegating

Java我的高效编程之常用函数

在开发的过程当中,一些经常用到的函数可以自己保存起来,下次需要使用的时候可以复制粘贴,这样可以大大提高效率.下面博主介绍自己的的几个工具类:时间函数库.文件处理函数库.对象的复制 下面附上代码说明: (1)时间函数库 package com.luo.util; import java.text.ParseException; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Ca

Spring Security-- 验证码功能的实现

spring security4 添加验证码 http://www.itwendao.com/article/detail/165400.html http://www.itdadao.com/articles/c15a754492p0.html     @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() {

Spring源码剖析——Bean的配置与启动

IOC介绍   相信大多数人在学习Spring时 IOC 和 Bean 算得上是最常听到的两个名词,IOC在学习Spring当中出现频率如此之高必然有其原因.如果我们做一个比喻的话,把Bean说成Spring中主角的话,那么IOC便是这个主角进行演出的舞台,没有IOC作为Bean的承载,那么Bean便不会在编程中大放异彩.作为Spring核心组件的重要一员,了解其内部实现对我们编程和窥探Spring内幕是相当有帮助的,下面一步步从源码的角度来剖析IOC究竟是怎样实现的. 接口设计   首先我们先

SpringSecurity+JPA+CAS单点登录

问题描述 SpringSecurity+JPA+CAS单点登录错误信息如下:ERRORContextLoader:220-Contextinitializationfailedorg.springframework.beans.factory.BeanDefinitionStoreException:UnexpectedexceptionparsingXMLdocumentfromServletContextresource[/WEB-INF/classes/applicationContext

mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题

我们公司的项目使用spring+mybatis组合.所以就必须得使用mybatis-spring了.所以此处就昨日mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题,做了一个总结. 我们可以先来看看mybatis-spring框架的1.1.1版本中关于SqlSessionDaoSupport的代码吧: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 3