3

Я работаю над веб-приложением с Spring MVC.

Это исключение я получаю:

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 

У меня есть контроллер: 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); 

     . . . 
    } 

    . . . 
} 

Это 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); 
    } 

    . . . 
} 

И, наконец, это 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; 
    } 

    . . . 
} 

Каждый из этих классов, кроме StudentController.java определяются как бобы в пределах 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> 

Я написал несколько JUnit тестов для этих классов, и они прекрасно работают, но всякий раз, когда я пытаюсь установить его на моем GlassFish сервере, он дает мне эту ошибку. Полный Stack Trace говорит, что он не может авторизовать вложенные зависимости в классах. Я не знаю, как решить эту проблему. Они пытались решить его на весь день. Этот SO post является подобной проблемой, с которой я столкнулся, но OP не оставил никакого решения.

Пожалуйста, помогите. Спасибо.

Частичное Трассировка стека:

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: Полное приложение-context.xml добавляется по запросу.

ответ

3

Удостоверьтесь, что у вас установлена ​​установка proxy-target-class флага в контексте весны.

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> 
+0

Это не сработало. Изначально в моем application-context.xml у меня был '', теперь я изменил его на ' '. Но он все равно дает мне такое же сообщение об ошибке. «... Инъекция автоуведомленных зависимостей не удалась ...» –

+0

Возможно ли, чтобы вы разместили подробную версию своего приложения-контекста, пожалуйста. – yogidilip

+0

Я отредактировал вопрос, чтобы добавить свое полное 'application-context.xml'. Пожалуйста, проверьте. –