title: Spring error: nested exception is java.lang.IllegalArgumentException: Class name must not be null
body: <p>I am currently working on a Spring Security project: Web-application with registration &amp; log-in functions.</p>
  
  <p>The code that will be given later below is from a Udemy course and I am just learning it.</p>
  
  <p>The code seems correct to me, but it throws an exception like this. </p>
  
  <pre><code>(root cause)
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
  creating bean with name 'demoSecurityConfig': Unsatisfied dependency 
  expressed through field 'userService'; nested exception is 
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
  creating bean with name 'userServiceImpl': Unsatisfied dependency expressed 
  through field 'userDao'; nested exception is 
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
  creating bean with name 'userDaoImpl': Unsatisfied dependency expressed 
  through field 'sessionFactory'; nested exception is 
  org.springframework.beans.factory.BeanCreationException: Error creating 
  bean with name 'sessionFactory' defined in 
  com.luv2code.springsecurity.demo.config.DemoAppConfig: Invocation of init 
  method failed; nested exception is java.lang.IllegalArgumentException: 
  Class name must not be null
  </code></pre>
  
  <p>If you look at the thrown exception, it has multiple nested exceptions on and on until it reaches the DemoAppConfig.class, so it looks like the @Autowired annotations work fine to me. </p>
  
  <p>For me, it looks like the fundamental problem of this exception is caused by this. </p>
  
  <pre><code>java.lang.IllegalArgumentException: Class name must not be null
  </code></pre>
  
  <p>However, I can't find a solution to fix this issue. I found a post that talks about this issue which was written in 2013. It says that I need to import these dependencies</p>
  
  <pre><code>&lt;dependencies&gt;
    &lt;!-- ... other dependency elements ... --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
      &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
      &lt;version&gt;3.2.0.CI-SNAPSHOT&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
      &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
      &lt;version&gt;3.2.0.CI-SNAPSHOT&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;repositories&gt;
    &lt;!-- ... possibly other repository elements ... --&gt;
    &lt;repository&gt;
      &lt;id&gt;spring-snapshots&lt;/id&gt;
      &lt;url&gt;https://repo.springsource.org/snapshot&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;
  </code></pre>
  
  <p>However, It does not work. </p>
  
  <p>As it seems that the main cause of the problem is in DemoAppConfig.class, I will only copy and paste the portion of the source code of wired classes, which is enough to show you how they are wired to each other, except the DemoAppConfig.class.</p>
  
  <p>Here is the code. </p>
  
  <p>DemoSecurityConfig.class</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
  
      //UserService는 UserDetailsService를 extends하는 interface이다.
      @Autowired
      private UserService userService;
  </code></pre>
  
  <p>UserService.class</p>
  
  <pre><code>public interface UserService extends UserDetailsService{
  
      User findByUserName(String userName);
  
      void save(CrmUser crmUser);
  }
  </code></pre>
  
  <p>UserServiceImpl.class</p>
  
  <pre><code>@Service
      public class UserServiceImpl implements UserService{
  
          @Autowired
          private UserDao userDao;
          @Autowired
          private BCryptPasswordEncoder passwordEncoder;
  </code></pre>
  
  <p>UserDao.class</p>
  
  <pre><code>public interface UserDao {
      User findByUserName(String userName);
  
      void save(User user);
  }
  </code></pre>
  
  <p>UserDaoImpl.class</p>
  
  <pre><code>@Repository
  public class UserDaoImpl implements UserDao {
  
      // need to inject the session factory
      @Autowired
      private SessionFactory sessionFactory;
  </code></pre>
  
  <p>DemoAppConfig.class</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages="com.luv2code.springsecurity.demo")
  @PropertySource("classpath:persistence-oracle.properties")
  public class DemoAppConfig {
  
      @Autowired
      private Environment env;
  
      private Logger logger = Logger.getLogger(getClass().getName());
  
      // define a bean for ViewResolver
  
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  
          viewResolver.setPrefix("/WEB-INF/view/");
          viewResolver.setSuffix(".jsp");
  
          return viewResolver;
      }
  
      @Bean
      public DataSource securityDataSource() {
  
          ComboPooledDataSource securityDataSource
              = new ComboPooledDataSource();
  
          try {
              securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
          } catch (PropertyVetoException e) {
              // TODO Auto-generated catch block
              throw new RuntimeException(e);
          }
  
          logger.info("&gt;&gt;&gt; jdbc.url=" + env.getProperty("jdbc.url"));
          logger.info("&gt;&gt;&gt; jdbc.user=" + env.getProperty("jdbc.user"));
  
          securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
          securityDataSource.setUser(env.getProperty("jdbc.user"));
          securityDataSource.setPassword(env.getProperty("jdbc.password"));
  
          securityDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
          securityDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
          securityDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
          securityDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
  
          return securityDataSource;
      }
  
      private int getIntProperty(String propName) {
          String propVal = env.getProperty(propName);
  
          int intPropVal = Integer.parseInt(propVal);
  
          return intPropVal;
      }
  
      private Properties getHibernateProperties() {
  
          // set hibernate properties
          Properties props = new Properties();
  
          props.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
          props.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
  
          return props;               
      }
  
  
      @Bean
      public LocalSessionFactoryBean sessionFactory(){
  
          // create session factories
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
  
          // set the properties
          sessionFactory.setDataSource(securityDataSource());
          sessionFactory.setPackagesToScan(env.getProperty("hiberante.packagesToScan"));
          sessionFactory.setHibernateProperties(getHibernateProperties());
  
          return sessionFactory;
      }
  
      @Bean
      @Autowired
      public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
  
          // setup transaction manager based on session factory
          HibernateTransactionManager txManager = new HibernateTransactionManager();
          txManager.setSessionFactory(sessionFactory);
  
          return txManager;
      }   
  
  
  }
  </code></pre>
  
  <p>Let me know if you need more information, and thank you for your support.</p>