gpt4 book ai didi

java - 没有定义名为 'transactionInterceptor' 的 bean

转载 作者:行者123 更新时间:2023-11-30 08:35:48 26 4
gpt4 key购买 nike

伙计们。我正在尝试学习 Java SSH 框架。但有些问题真的阻止了我。这是 applicationContext.xml:

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/xman"/>
<property name="username" value="root"/>
<property name="password" value="xman"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.connection.url">
jdbc:mysql://localhost:3306/xman
</prop>
<prop key="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/model/AccountEntity.hbm.xml</value>
<value>org/model/DraftEntity.hbm.xml</value>
<value>org/model/PostEntity.hbm.xml</value>
</list>
</property>
</bean>


<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>accountService</value>
<value>draftService</value>
<value>postService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>
transactionInterceptor
</value>
</list>
</property>
</bean>

<!-- Dao -->
<bean id="accountDao" class="org.dao.imp.AccountDaoImp">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="draftDao" class="org.dao.imp.DraftDaoImp">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="postDao" class="org.dao.imp.PostDaoImp">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- Service -->
<bean id="accountService" class="org.service.imp.AccountServiceManage">
<property name="accountDao">
<ref bean="accountDao"/>
</property>
</bean>
<bean id="draftService" class="org.service.imp.DraftServiceManage">
<property name="draftDao">
<ref bean="draftDao"/>
</property>
</bean>
<bean id="postService" class="org.service.imp.PostServiceManage">
<property name="postDao">
<ref bean="postDao"/>
</property>
</bean>

正如你在上面看到的,我已经有了名为 transactionInterceptor 的 bean,但是 Intellij idea 仍然会抛出这样的错误:

24-Jun-2016 12:42:43.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.0.M6
24-Jun-2016 12:42:43.021 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: May 11 2016 21:43:59 UTC
24-Jun-2016 12:42:43.021 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.0.0
24-Jun-2016 12:42:43.021 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
24-Jun-2016 12:42:43.021 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.12
24-Jun-2016 12:42:43.021 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
24-Jun-2016 12:42:43.022 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
24-Jun-2016 12:42:43.022 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_91-b14
24-Jun-2016 12:42:43.022 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
24-Jun-2016 12:42:43.022 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/geoferry/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_geniusBlog_2
24-Jun-2016 12:42:43.022 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/geoferry/Documents/apache-tomcat-9.0.0.M6
24-Jun-2016 12:42:43.023 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/geoferry/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_geniusBlog_2/conf/logging.properties
24-Jun-2016 12:42:43.025 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
24-Jun-2016 12:42:43.026 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
24-Jun-2016 12:42:43.027 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
24-Jun-2016 12:42:43.029 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
24-Jun-2016 12:42:43.030 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
24-Jun-2016 12:42:43.034 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
24-Jun-2016 12:42:43.034 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
24-Jun-2016 12:42:43.035 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/geoferry/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_geniusBlog_2
24-Jun-2016 12:42:43.036 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/geoferry/Documents/apache-tomcat-9.0.0.M6
24-Jun-2016 12:42:43.036 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/geoferry/Documents/apache-tomcat-9.0.0.M6/temp
24-Jun-2016 12:42:43.037 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/geoferry/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
24-Jun-2016 12:42:43.632 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
24-Jun-2016 12:42:43.675 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Jun-2016 12:42:43.704 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
24-Jun-2016 12:42:43.706 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Jun-2016 12:42:43.706 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1745 ms
24-Jun-2016 12:42:43.756 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
24-Jun-2016 12:42:43.756 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M6
24-Jun-2016 12:42:43.767 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
24-Jun-2016 12:42:43.778 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
24-Jun-2016 12:42:43.781 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 74 ms
Connected to server
[2016-06-24 12:42:43,911] Artifact geniusBlog:war exploded: Artifact is being deployed, please wait...
24-Jun-2016 12:42:48.285 INFO [RMI TCP Connection(4)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
24-Jun-2016 12:42:48.402 INFO [RMI TCP Connection(4)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
24-Jun-2016 12:42:48.693 INFO [RMI TCP Connection(4)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Fri Jun 24 12:42:48 CST 2016]; root of context hierarchy
24-Jun-2016 12:42:48.827 INFO [RMI TCP Connection(4)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
24-Jun-2016 12:42:49.808 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.annotations.common.Version.<clinit> HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
24-Jun-2016 12:42:49.828 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.Version.logVersion HHH000412: Hibernate Core {4.2.2.Final}
24-Jun-2016 12:42:49.835 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
24-Jun-2016 12:42:49.839 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
24-Jun-2016 12:42:51.063 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
24-Jun-2016 12:42:51.110 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.engine.jdbc.internal.LobCreatorBuilder.useContextualLobCreation HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
24-Jun-2016 12:42:51.303 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.engine.transaction.internal.TransactionFactoryInitiator.initiateService HHH000399: Using default transaction strategy (direct JDBC transactions)
24-Jun-2016 12:42:51.341 INFO [RMI TCP Connection(4)-127.0.0.1] org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.<init> HHH000397: Using ASTQueryTranslatorFactory
24-Jun-2016 12:42:51.828 INFO [RMI TCP Connection(4)-127.0.0.1] org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet Using DataSource [org.apache.commons.dbcp.BasicDataSource@1f126f6] of Hibernate SessionFactory for HibernateTransactionManager
24-Jun-2016 12:42:51.894 WARNING [RMI TCP Connection(4)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '
transactionInterceptor
' is defined
24-Jun-2016 12:42:51.897 SEVERE [RMI TCP Connection(4)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '
transactionInterceptor
' is defined
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
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:775)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4732)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5194)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '
transactionInterceptor
' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:701)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1180)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.resolveInterceptorNames(AbstractAutoProxyCreator.java:549)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildAdvisors(AbstractAutoProxyCreator.java:511)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:457)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:350)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
... 56 more

24-Jun-2016 12:42:51.900 SEVERE [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
24-Jun-2016 12:42:51.929 SEVERE [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors

希望有人能帮助我,谢谢!

最佳答案

只需修剪 transactionInterceptor 周围的空白。

将所有内容放在同一行,不要换行等。

关于java - 没有定义名为 'transactionInterceptor' 的 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38005892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com