title: java.lang.IllegalArgumentException: Cannot set to com.sun.proxy.$Proxy
body: <p>I am working on a web-app with Spring MVC.</p>
  
  <p>This is the exception I am getting:</p>
  
  <pre><code>Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: Can not set com.onclave.papercraft.DAO.tenantDAO.Implementation.UsersDAOImplementation field com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController.usersDAOImplementation to com.sun.proxy.$Proxy301
  </code></pre>
  
  <p>I have a controller:
  <code>StudentController.java</code></p>
  
  <pre><code>@Controller
  public class StudentsController {
  
      @Autowired
      private UsersDAOController usersDAOController;
  
      . . .
  
      private final String USER_TYPE = "student";
  
      @Transactional
      @RequestMapping(value = "/PAuth/user/add/user/student", method = RequestMethod.POST)
      public long addNewStudent(HttpServletRequest request) {
  
          long usersID = -1;
  
          . . .
  
          usersID = usersDAOController.storeNewUser(request, USER_TYPE);
  
          . . .
      }
  
      . . .
  }
  </code></pre>
  
  <p>This is the <code>UsersDAOController.java</code>:</p>
  
  <pre><code>@Controller
  @Configurable
  public class UsersDAOController {
  
      @Autowired
      private UsersDAOImplementation usersDAOImplementation;
  
      public long storeNewUser(HttpServletRequest request, final String USER_TYPE) {
  
          Users user = new Users();
  
          . . .
  
          return usersDAOImplementation.createNewUser(user);
      }
  
      . . .
  }
  </code></pre>
  
  <p>And finally, this is the <code>UsersDAOImplementation.java</code>:</p>
  
  <pre><code>@Service
  public class UsersDAOImplementation implements IUsersDAO {
  
      private JdbcTemplate jdbcTemplate = null;
  
      @Autowired
      public UsersDAOImplementation(DataSource dataSource) {
          this.jdbcTemplate = (new JdbcTemplate(dataSource));
      }
  
      . . .
  
      @Override
      public long createNewUser(final Users user) {
  
          KeyHolder keyHolder = new GeneratedKeyHolder();
  
          final long success = this.jdbcTemplate.update(new PreparedStatementCreator() {
              @Override
              public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                  PreparedStatement preparedStatement = connection.prepareStatement(QueryStatements.INSERT_NEW_USER_SQL, Statement.RETURN_GENERATED_KEYS);
  
                  . . .
  
                  return preparedStatement;
              }
          }, keyHolder);
  
          if(success == 1) {
              return keyHolder.getKey().longValue();
          }
  
          return -1;
      }
  
      . . .
  }
  </code></pre>
  
  <p>Each of these classes except the <code>StudentController.java</code> are defined as beans within the <code>application-context.xml</code>.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;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" 
      xmlns:mvc="http://www.springframework.org/schema/mvc" 
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:aop="http://www.springframework.org/schema/aop"    
      xmlns:task="http://www.springframework.org/schema/task" 
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
                          http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-4.1.xsd    
                          http://www.springframework.org/schema/util 
                          http://www.springframework.org/schema/util/spring-util-4.1.xsd   
                          http://www.springframework.org/schema/jdbc 
                          http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd             
                          http://www.springframework.org/schema/aop 
                          http://www.springframework.org/schema/aop/spring-aop-4.1.xsd    
                          http://www.springframework.org/schema/task 
                          http://www.springframework.org/schema/task/spring-task-4.1.xsd 
                          http://www.springframework.org/schema/tx 
                          http://www.springframework.org/schema/tx/spring-tx.xsd 
                          http://www.springframework.org/schema/mvc 
                          http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsd" xmlns:cache="http://www.springframework.org/schema/cache"&gt;
  
      &lt;!-- External Properties Placeholder Configuration --&gt;
      &lt;context:property-placeholder location="classpath*:properties/database-connectivity.properties" order="1" ignore-unresolvable="true" /&gt;
  
      &lt;!-- Configuring Transaction Manager --&gt;
      &lt;tx:annotation-driven proxy-target-class="true" /&gt;
  
      &lt;!--
          ===========================================================
                         SETTINGS/CONFIGURATION BEANS
          ===========================================================
      --&gt;
  
      &lt;!-- REST template configuration --&gt;
      &lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/&gt;
  
      &lt;!--
          ===========================================================
                       DATABASE CONNECTIVITY CONFIGURATION
          ===========================================================
      --&gt;
  
      &lt;!-- Database Connectivity Bean configuration --&gt;
      &lt;bean
          id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  
          &lt;property name="driverClassName" value="${jdbc.mysql.driverClass}" /&gt;
          &lt;property name="url" value="${jdbc.mysql.url}" /&gt;
          &lt;property name="username" value="${jdbc.mysql.username}" /&gt;
          &lt;property name="password" value="${jdbc.mysql.password}" /&gt;
  
      &lt;/bean&gt;
  
      &lt;!-- Transaction Manager Configuration --&gt;
      &lt;bean
          id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
          scope="singleton"&gt;
  
          &lt;property name="dataSource" ref="dataSource" /&gt;
  
      &lt;/bean&gt;
  
      &lt;!--
          ===========================================================
                              BEAN DEFINITIONS
          ===========================================================
      --&gt;
  
      &lt;!-- User Controller Beans --&gt;
  
      &lt;bean
          id="usersDAOControllerBean"
          class="com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController"&gt;
  
      &lt;/bean&gt;
  
      &lt;bean
          id="usersDAOImplementationBean"
          class="com.onclave.papercraft.DAO.tenantDAO.Implementation.UsersDAOImplementation"&gt;
  
          &lt;constructor-arg ref="dataSource" /&gt;
  
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I wrote some JUnit Test Cases for these classes and they are working fine, but whenever I am trying to deploy it on my GlassFish server, it is giving me this error. The full Stack Trace says it fails to autowire the injected dependencies in the classes. I have no idea how to solve  this problem. Have been trying to solve it for the whole day. This <a href="https://stackoverflow.com/questions/27540355/could-not-autowire-field-cant-to-com-sun-proxy-proxy22">SO post</a> is kind of the similar problem I am facing but the OP did not leave any solution.</p>
  
  <p>Please help. Thank you.</p>
  
  <p>Partial Stack Trace:</p>
  
  <pre><code>WebModule[/Papercraft-web]StandardWrapper.Throwable
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController com.onclave.papercraft.controller.student.StudentsController.usersDAOController; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersDAOController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onclave.papercraft.DAO.tenantDAO.Implementation.UsersDAOImplementation com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController.usersDAOImplementation; nested exception is java.lang.IllegalArgumentException: Can not set com.onclave.papercraft.DAO.tenantDAO.Implementation.UsersDAOImplementation field com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController.usersDAOImplementation to com.sun.proxy.$Proxy301
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
      at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)
      at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:678)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
      at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5732)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:5977)
      at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
      at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
      at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
      at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:360)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:360)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
      at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
      at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
      at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <blockquote>
    <p><strong>EDIT:</strong>
    The complete application-context.xml is added as requested.</p>
  </blockquote>