java.lang.IllegalArgumentException

tip

If you're unit testing, you should instantiate only the service and mock the dependencies. If you're testing integration, you should add all the mocking to the configurations file.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • When <context:load-time-weaver aspectj-weaving="on" /> is used in the same application context as a bean defined via the factory-method and factory-bean functionality the following IllegalArgumentException is thrown: Exception in thread "main" java.lang.IllegalArgumentException: Name must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.util.ClassUtils.forName(ClassUtils.java:186) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1131) at org.springframework.beans.factory.support.AbstractBeanFactory.isBeanClassMatch(AbstractBeanFactory.java:1161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:172) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:474) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:340) Sample driver: package test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { System.out.println("Successful context is bootstrapping. It does not contain loadTimeWeaver."); ClassPathXmlApplicationContext successCtx = new ClassPathXmlApplicationContext("test-success.xml"); System.out.println("factory: " + successCtx.getBean("factory")); System.out.println("object: " + successCtx.getBean("object")); System.out.println("Failing context is bootstrapping. It is the same as successful, except for addition of loadTimeWeaver."); ClassPathXmlApplicationContext failCtx = new ClassPathXmlApplicationContext("test-fails.xml"); System.out.println("factory: " + failCtx.getBean("factory")); System.out.println("object: " + failCtx.getBean("object")); } } Associated simple factory: package test; public class Factory { public String getObject() { return "Hello world"; } } test-success.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="factory" class="test.Factory" /> <bean id="object" factory-bean="factory" factory-method="getObject" /> </beans> test-fails.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd"> <bean id="factory" class="test.Factory" /> <bean id="object" factory-bean="factory" factory-method="getObject" /> <context:load-time-weaver aspectj-weaving="on" /> </beans> By changing lines 1130-1132 of AbstractBeanFactory.java from: if (typeMatchOnly && getTempClassLoader() != null) { return ClassUtils.forName(mbd.getBeanClassName(), getTempClassLoader()); } to: if (typeMatchOnly && getTempClassLoader() != null) { return mbd.resolveBeanClass(getTempClassLoader()); } the above test code does bootstrap and run successfully. Additionally, the changed code above does still successfully apply @Aspect advice to non-spring managed objects in both a standalone and JBoss 4.2.0 environment. We do not currently have a case and haven't done any verification of the above change and its impact on advising spring managed beans.
    via by Casey Hadden,
  • When <context:load-time-weaver aspectj-weaving="on" /> is used in the same application context as a bean defined via the factory-method and factory-bean functionality the following IllegalArgumentException is thrown: Exception in thread "main" java.lang.IllegalArgumentException: Name must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.util.ClassUtils.forName(ClassUtils.java:186) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1131) at org.springframework.beans.factory.support.AbstractBeanFactory.isBeanClassMatch(AbstractBeanFactory.java:1161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:172) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:474) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:340) Sample driver: package test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { System.out.println("Successful context is bootstrapping. It does not contain loadTimeWeaver."); ClassPathXmlApplicationContext successCtx = new ClassPathXmlApplicationContext("test-success.xml"); System.out.println("factory: " + successCtx.getBean("factory")); System.out.println("object: " + successCtx.getBean("object")); System.out.println("Failing context is bootstrapping. It is the same as successful, except for addition of loadTimeWeaver."); ClassPathXmlApplicationContext failCtx = new ClassPathXmlApplicationContext("test-fails.xml"); System.out.println("factory: " + failCtx.getBean("factory")); System.out.println("object: " + failCtx.getBean("object")); } } Associated simple factory: package test; public class Factory { public String getObject() { return "Hello world"; } } test-success.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="factory" class="test.Factory" /> <bean id="object" factory-bean="factory" factory-method="getObject" /> </beans> test-fails.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd"> <bean id="factory" class="test.Factory" /> <bean id="object" factory-bean="factory" factory-method="getObject" /> <context:load-time-weaver aspectj-weaving="on" /> </beans> By changing lines 1130-1132 of AbstractBeanFactory.java from: if (typeMatchOnly && getTempClassLoader() != null) { return ClassUtils.forName(mbd.getBeanClassName(), getTempClassLoader()); } to: if (typeMatchOnly && getTempClassLoader() != null) { return mbd.resolveBeanClass(getTempClassLoader()); } the above test code does bootstrap and run successfully. Additionally, the changed code above does still successfully apply @Aspect advice to non-spring managed objects in both a standalone and JBoss 4.2.0 environment. We do not currently have a case and haven't done any verification of the above change and its impact on advising spring managed beans.
    via by Casey Hadden,
  • Spring Boot test class wont inject beans
    via Stack Overflow by rayman
    ,
  • Spring file upload by ajax
    via Stack Overflow by kris14an
    ,
    • java.lang.IllegalArgumentException: Name must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.util.ClassUtils.forName(ClassUtils.java:186) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1131) at org.springframework.beans.factory.support.AbstractBeanFactory.isBeanClassMatch(AbstractBeanFactory.java:1161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:172) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:474) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:340)

    Users with the same issue

    Andreas Häber
    3 times, last one,
    derprogger
    2 times, last one,
    tomthomas
    121 times, last one,
    tvrmsmith
    1 times, last one,
    osvzs
    2 times, last one,
    189 more bugmates