首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

采取spring mvc和hibernate开发,application.xml的配置求详细分析

2013-09-11 
采用spring mvc和hibernate开发,application.xml的配置求详细分析application.xml的配置求详细分析,在里面

采用spring mvc和hibernate开发,application.xml的配置求详细分析
application.xml的配置求详细分析,
在里面已经配好了 dao,service,controller,mapping 等,为什么前台请求传不到后台。
有不有好心人,能发个简单的配好的demo给我仔细参考阅读。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestTbCkeckboxController' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'TestTbCheckboxService' while setting bean property 'testTbCheckboxService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestTbCheckboxService' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

[解决办法]
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/mapping</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.generate_statistics">
${hibernate.generate_statistics}
</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
</bean>

<!--
Transaction manager for a single Hibernate SessionFactory (alternative
to JTA)
-->
<!--
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
-->


<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务的传播特性 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="write*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="execute*" propagation="SUPPORTS"
read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 哪些类的哪些方法参与事务 -->

<aop:config>
<aop:pointcut id="bizMethods"
expression="execution(* junsoft.tcmhm.Service.*.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
</aop:config>

[解决办法]
这个比较简单的配置,属于半配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>


</bean>
<!-- 配置事物管理器 通过sessionFactory管理session,session的开启,提交,回滚 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事物的传播性:环绕通知 -->
<tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="findAll*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

<!--自动生成代理对象 -->
<aop:config>
<!--定义一个切面,即定义哪些方法应用这些规则-->
<aop:pointcut id="bizMethod" expression="execution(* *..*Biz.*(..))"/>
<!--将事务通知和切面组合(织入)-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethod"/>
</aop:config>


<!-- 将sessionFactory注入到studentDao中 -->
<bean id="studentDAO" class="junsoft.dao.StudentDao">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!--将studentDao注入到StudentBiz中 -->
<bean id="studentBiz" class="junsoft.biz.StudentBizImpl">
<property name="studentDao">
<ref local="studentDAO"/>
</property>
</bean>
<!-- studentBiz注入到StudentAction中 -->
<bean id="studentAction" class="junsoft.action.StudentAction" scope="prototype" >
<property name="studentBiz">
<ref local="studentBiz"/>
</property>
</bean>
[解决办法]
顶,同求一个用上spring mvc的实例demo!
[解决办法]
看错误提示,应该是事务没有配置好,在看看
[解决办法]
楼主给你个链接,一个小例子:http://download.csdn.net/detail/dw_java08/4542586 楼主参考参考。
[解决办法]
你把你的配置文件 发出来看看 应该是你的配置文件 不对
[解决办法]
你是spring mvc不能用是因为你的web.xml中没有配置spring的mvc使用,默认是不使用spring的mvc
[解决办法]
大家都给你意见了,如果楼主还没有解决掉的话发我私信把。我给你个demo的例子。

热点排行