我正在尝试在DepartmentService中注入DepartmentDAO。这是在我添加@Transactional注释后出现的。所以这是我的DepartmentService:
@Service
@Transactional
public class DepartmentService extends AbstractCRUDService<DepartmentDTO> {
private DepartmentDAO departmentDAO;
public DepartmentService() {
super();
this.departmentDAO = null;
}
@Inject
public DepartmentService(DepartmentDAO departmentDAO) {
super();
this.departmentDAO = departmentDAO;
}
@Override
public Long create(DepartmentDTO dDTO) {
Department department = new Department();
department.setDepName(dDTO.getDepName());
return departmentDAO.create(department);
}
...............read,update,delete,findAll methods...........................
}
这是我的部门代码:
@Repository
@Transactional(propagation = Propagation.MANDATORY)
public class DepartmentDAO extends AbstractCRUDDao<Department> {
private final Logger logger = LoggerFactory.getLogger(DepartmentDAO.class);
protected Class<DepartmentDAO> clazz;
public DepartmentDAO() {
}
@Override
public Long create(Department d) {
entityManager.persist(d);
return d.getId();
}
...............read,update,delete,findAll methods...........................
}
这是一个applicationContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<context:annotation-config />
<context:component-scan base-package="net.sam" />
<context:component-scan base-package="net.sam.servlets" />
<context:component-scan base-package="net.sam.dao.impl" />
<context:component-scan base-package="net.sam.services.impl" />
<context:component-scan base-package="net.sam.model.impl" />
<!-- declare EntityManagerFactory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="net.sam.jpa" />
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
</bean>
<!-- inject into JPATransactionManager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<!-- enable container managed transactions -->
<tx:annotation-driven transaction-manager="transactionManager" />
我的堆栈跟踪:
мар 29, 2013 4:46:35 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production envi
ronments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\
bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/
bin;C:/Program Files/Java/jre7/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\W
INDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\Mercurial\;C:\Program Files\Microsoft SQL Se
rver\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\TortoiseSV
N\bin;c:\Program Files\apache-maven-3.0.4-bin\apache-maven-3.0.4\bin;C:\Program Files\eclipse;;.
мар 29, 2013 4:46:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.e
clipse.jst.jee.server:chardymov-webapp' did not find a matching property.
мар 29, 2013 4:46:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
мар 29, 2013 4:46:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1710 ms
мар 29, 2013 4:46:35 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
мар 29, 2013 4:46:35 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35
мар 29, 2013 4:46:38 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
мар 29, 2013 4:46:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
29-03-13 16:46:38,669 INFO [ContextLoader:initWebApplicationContext:272] - Root WebApplicationConte
xt: initialization started
29-03-13 16:46:38,741 INFO [XmlWebApplicationContext:prepareRefresh:503] - Refreshing Root WebAppli
cationContext: startup date [Fri Mar 29 16:46:38 EAT 2013]; root of context hierarchy
29-03-13 16:46:38,797 INFO [XmlBeanDefinitionReader:loadBeanDefinitions:315] - Loading XML bean def
initions from URL [file:/C:/Documents%20and%20Settings/mach/workspace/clean2/.metadata/.plugins/org.
eclipse.wst.server.core/tmp0/wtpwebapps/chardymov-webapp/WEB-INF/classes/applicationContext.xml]
29-03-13 16:46:39,270 INFO [AutowiredAnnotationBeanPostProcessor:<init>:139] - JSR-330 'javax.injec
t.Inject' annotation found and supported for autowiring
29-03-13 16:46:39,374 INFO [LocalContainerEntityManagerFactoryBean:createNativeEntityManagerFactory
:283] - Building JPA container EntityManagerFactory for persistence unit 'net.sam.jpa'
29-03-13 16:46:39,599 INFO [Version:<clinit>:37] - HCANN000001: Hibernate Commons Annotations {4.0.
1.Final}
29-03-13 16:46:39,599 INFO [Version:logVersion:41] - HHH000412: Hibernate Core {4.1.9.Final}
29-03-13 16:46:39,607 INFO [Environment:<clinit>:239] - HHH000206: hibernate.properties not found
29-03-13 16:46:39,607 INFO [Environment:buildBytecodeProvider:342] - HHH000021: Bytecode provider n
ame : javassist
29-03-13 16:46:39,647 INFO [Ejb3Configuration:configure:527] - HHH000204: Processing PersistenceUni
tInfo [
name: net.sam.jpa
...]
29-03-13 16:46:39,960 INFO [DriverManagerConnectionProviderImpl:configure:96] - HHH000402: Using Hi
bernate built-in connection pool (not for production use!)
29-03-13 16:46:39,960 INFO [DriverManagerConnectionProviderImpl:configure:130] - HHH000115: Hiberna
te connection pool size: 20
29-03-13 16:46:39,960 INFO [DriverManagerConnectionProviderImpl:configure:133] - HHH000006: Autocom
mit mode: true
29-03-13 16:46:39,960 INFO [DriverManagerConnectionProviderImpl:configure:147] - HHH000401: using d
river [org.h2.Driver] at URL [jdbc:h2:tcp://localhost/mem:db1]
29-03-13 16:46:39,960 INFO [DriverManagerConnectionProviderImpl:configure:152] - HHH000046: Connect
ion properties: {autocommit=true, release_mode=auto}
29-03-13 16:46:40,104 INFO [Dialect:<init>:123] - HHH000400: Using dialect: org.hibernate.dialect.H
2Dialect
29-03-13 16:46:40,144 INFO [TransactionFactoryInitiator:initiateService:73] - HHH000268: Transactio
n strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
29-03-13 16:46:40,152 INFO [ASTQueryTranslatorFactory:<init>:48] - HHH000397: Using ASTQueryTransla
torFactory
29-03-13 16:46:40,217 INFO [Version:<clinit>:27] - HV000001: Hibernate Validator 4.3.1.Final
29-03-13 16:46:40,570 INFO [SchemaExport:execute:343] - HHH000227: Running hbm2ddl schema export
Hibernate: alter table EMPLOYEES drop constraint FK4351FF658ECC7308
29-03-13 16:46:40,578 ERROR [SchemaExport:perform:425] - HHH000389: Unsuccessful: alter table EMPLOY
EES drop constraint FK4351FF658ECC7308
29-03-13 16:46:40,578 ERROR [SchemaExport:perform:426] - Table "EMPLOYEES" not found; SQL statement:
alter table EMPLOYEES drop constraint FK4351FF658ECC7308 [42102-170]
Hibernate: alter table EMPLOYEES drop constraint FK4351FF6530EEAB88
29-03-13 16:46:40,578 ERROR [SchemaExport:perform:425] - HHH000389: Unsuccessful: alter table EMPLOY
EES drop constraint FK4351FF6530EEAB88
29-03-13 16:46:40,578 ERROR [SchemaExport:perform:426] - Table "EMPLOYEES" not found; SQL statement:
alter table EMPLOYEES drop constraint FK4351FF6530EEAB88 [42102-170]
Hibernate: drop table DEPARTMENTS if exists
Hibernate: drop table EMPLOYEES if exists
Hibernate: drop table ROLES if exists
Hibernate: create table DEPARTMENTS (id bigint generated by default as identity, depName varchar(20)
not null unique, primary key (id))
Hibernate: create table EMPLOYEES (id bigint generated by default as identity, name varchar(20) not
null, surname varchar(255), department_fk bigint not null, role_fk bigint not null, primary key (id)
, unique (name, surname))
Hibernate: create table ROLES (id bigint generated by default as identity, roleName varchar(20) not
null unique, primary key (id))
Hibernate: alter table EMPLOYEES add constraint FK4351FF658ECC7308 foreign key (department_fk) refer
ences DEPARTMENTS
Hibernate: alter table EMPLOYEES add constraint FK4351FF6530EEAB88 foreign key (role_fk) references
ROLES
29-03-13 16:46:40,602 INFO [SchemaExport:execute:405] - HHH000230: Schema export complete
29-03-13 16:46:40,674 INFO [DefaultListableBeanFactory:preInstantiateSingletons:577] - Pre-instanti
ating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d98539: de
fining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.sp
ringframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.an
notation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAn
notationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,comp
osite,departmentDAO,employeeDAO,roleDAO,departmentService,employeeService,roleService,entityManagerF
actory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframewor
k.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.inte
rceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,o
rg.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of
factory hierarchy
29-03-13 16:46:40,730 INFO [DefaultListableBeanFactory:destroySingletons:434] - Destroying singleto
ns in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d98539: defining beans [
org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.
context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.inter
nalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProces
sor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,composite,departme
ntDAO,employeeDAO,roleDAO,departmentService,employeeService,roleService,entityManagerFactory,transac
tionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.
annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.Transa
ctionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframe
work.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hiera
rchy
29-03-13 16:46:40,738 INFO [LocalContainerEntityManagerFactoryBean:destroy:441] - Closing JPA Entit
yManagerFactory for persistence unit 'net.sam.jpa'
29-03-13 16:46:40,738 INFO [SchemaExport:execute:343] - HHH000227: Running hbm2ddl schema export
Hibernate: alter table EMPLOYEES drop constraint FK4351FF658ECC7308
Hibernate: alter table EMPLOYEES drop constraint FK4351FF6530EEAB88
Hibernate: drop table DEPARTMENTS if exists
Hibernate: drop table EMPLOYEES if exists
Hibernate: drop table ROLES if exists
29-03-13 16:46:40,746 INFO [SchemaExport:execute:405] - HHH000230: Schema export complete
29-03-13 16:46:40,746 INFO [DriverManagerConnectionProviderImpl:stop:156] - HHH000030: Cleaning up
connection pool [jdbc:h2:tcp://localhost/mem:db1]
29-03-13 16:46:40,746 ERROR [ContextLoader:initWebApplicationContext:307] - Context initialization f
ailed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com
posite' defined in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugins\org.ecli
pse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\Composite.cla
ss]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sam_sol
utions.services.impl.DepartmentService]: : Error creating bean with name 'departmentService' defined
in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugins\org.eclipse.wst.server.
core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\services\impl\DepartmentServ
ice.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstanti
ationException: Could not instantiate bean class [net.sam.services.impl.DepartmentService]
: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argumen
t type mismatch; nested exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'departmentService' defined in file [C:\Documents and Settings\mach\workspac
e\clean2\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\cla
sses\net\sam\services\impl\DepartmentService.class]: Instantiation of bean failed; nested
exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[net.sam.services.impl.DepartmentService]: Illegal arguments for constructor; nested excep
tion is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorRes
olver.java:730)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:196)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor
(AbstractAutowireCapableBeanFactory.java:1035)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(
AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(De
faultListableBeanFactory.java:605)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(A
bstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContex
t.java:472)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLo
ader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.j
ava:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd
epartmentService' defined in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugin
s\org.eclipse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\ser
vices\impl\DepartmentService.class]: Instantiation of bean failed; nested exception is org.springfra
mework.beans.BeanInstantiationException: Could not instantiate bean class [net.sam.service
s.impl.DepartmentService]: Illegal arguments for constructor; nested exception is java.lang.IllegalA
rgumentException: argument type mismatch
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor
(AbstractAutowireCapableBeanFactory.java:1035)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(
AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(Defa
ultListableBeanFactory.java:872)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(Default
ListableBeanFactory.java:814)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultLi
stableBeanFactory.java:731)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(Construct
orResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorRes
olver.java:723)
... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [n
et.sam.services.impl.DepartmentService]: Illegal arguments for constructor; nested excepti
on is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:158)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstanti
ationStrategy.java:121)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:280)
... 38 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 40 more
мар 29, 2013 4:46:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframewor
k.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com
posite' defined in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugins\org.ecli
pse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\Composite.cla
ss]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sam_sol
utions.services.impl.DepartmentService]: : Error creating bean with name 'departmentService' defined
in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugins\org.eclipse.wst.server.
core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\services\impl\DepartmentServ
ice.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstanti
ationException: Could not instantiate bean class [net.sam.services.impl.DepartmentService]
: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argumen
t type mismatch; nested exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'departmentService' defined in file [C:\Documents and Settings\mach\workspac
e\clean2\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\cla
sses\net\sam\services\impl\DepartmentService.class]: Instantiation of bean failed; nested
exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[net.sam.services.impl.DepartmentService]: Illegal arguments for constructor; nested excep
tion is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorRes
olver.java:730)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:196)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor
(AbstractAutowireCapableBeanFactory.java:1035)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(
AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(De
faultListableBeanFactory.java:605)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(A
bstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContex
t.java:472)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLo
ader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.j
ava:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd
epartmentService' defined in file [C:\Documents and Settings\mach\workspace\clean2\.metadata\.plugin
s\org.eclipse.wst.server.core\tmp0\wtpwebapps\chardymov-webapp\WEB-INF\classes\net\sam\ser
vices\impl\DepartmentService.class]: Instantiation of bean failed; nested exception is org.springfra
mework.beans.BeanInstantiationException: Could not instantiate bean class [net.sam.service
s.impl.DepartmentService]: Illegal arguments for constructor; nested exception is java.lang.IllegalA
rgumentException: argument type mismatch
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor
(AbstractAutowireCapableBeanFactory.java:1035)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(
AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(Defa
ultListableBeanFactory.java:872)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(Default
ListableBeanFactory.java:814)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultLi
stableBeanFactory.java:731)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(Construct
orResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorRes
olver.java:723)
... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [n
et.sam.services.impl.DepartmentService]: Illegal arguments for constructor; nested excepti
on is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:158)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstanti
ationStrategy.java:121)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorRes
olver.java:280)
... 38 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 40 more
мар 29, 2013 4:46:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
мар 29, 2013 4:46:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/chardymov-webapp] startup failed due to previous errors
мар 29, 2013 4:46:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
мар 29, 2013 4:46:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/chardymov-webapp] registered the JDBC driver [org.h2.Driver] but faile
d to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver h
as been forcibly unregistered.
мар 29, 2013 4:46:40 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
мар 29, 2013 4:46:40 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9757 ms
答案 0 :(得分:4)
@Transactional
是作为代理实现的,IMHO Spring不会将代理类型解析为DepartmentDAO
。在这种情况下,您有两个解决方案: