3

I am working on a web-app with Spring MVC.

This is the exception I am getting:

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

I have a controller: StudentController.java

@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);

        . . .
    }

    . . .
}

This is the UsersDAOController.java:

@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);
    }

    . . .
}

And finally, this is the UsersDAOImplementation.java:

@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;
    }

    . . .
}

Each of these classes except the StudentController.java are defined as beans within the application-context.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" 
    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">

    <!-- External Properties Placeholder Configuration -->
    <context:property-placeholder location="classpath*:properties/database-connectivity.properties" order="1" ignore-unresolvable="true" />

    <!-- Configuring Transaction Manager -->
    <tx:annotation-driven proxy-target-class="true" />

    <!--
        ===========================================================
                       SETTINGS/CONFIGURATION BEANS
        ===========================================================
    -->

    <!-- REST template configuration -->
    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>

    <!--
        ===========================================================
                     DATABASE CONNECTIVITY CONFIGURATION
        ===========================================================
    -->

    <!-- Database Connectivity Bean configuration -->
    <bean
        id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="driverClassName" value="${jdbc.mysql.driverClass}" />
        <property name="url" value="${jdbc.mysql.url}" />
        <property name="username" value="${jdbc.mysql.username}" />
        <property name="password" value="${jdbc.mysql.password}" />

    </bean>

    <!-- Transaction Manager Configuration -->
    <bean
        id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
        scope="singleton">

        <property name="dataSource" ref="dataSource" />

    </bean>

    <!--
        ===========================================================
                            BEAN DEFINITIONS
        ===========================================================
    -->

    <!-- User Controller Beans -->

    <bean
        id="usersDAOControllerBean"
        class="com.onclave.papercraft.DAO.tenantDAO.Controller.UsersDAOController">

    </bean>

    <bean
        id="usersDAOImplementationBean"
        class="com.onclave.papercraft.DAO.tenantDAO.Implementation.UsersDAOImplementation">

        <constructor-arg ref="dataSource" />

    </bean>

</beans>

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 SO post is kind of the similar problem I am facing but the OP did not leave any solution.

Please help. Thank you.

Partial Stack Trace:

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)

EDIT: The complete application-context.xml is added as requested.

1 Answer 1

6

Please make sure you have proxy-target-class flag setup as true in your spring context.

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
Sign up to request clarification or add additional context in comments.

3 Comments

This did not work. Initially in my application-context.xml I had <tx:annotation-driven />, now I changed it to <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>. But it is still giving me the same error message. " ... Injection of autowired dependencies failed ... "
Is it possible for you to post a detailed version of your application-context please.
I have edited the question to add my complete application-context.xml. Please check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.