- 浏览: 200588 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
DRUNKonSTREET:
找了忒久了,谢谢
JNDI到底是什么,有什么作用 -
xiaozang:
非常感谢
JNDI到底是什么,有什么作用 -
yong7356:
学习了。。。。。。
android AVD 详解 -
ocaicai:
简洁明了,写得真好啊
简简单单储存过程——循环一个select结果集 -
wang4674890:
天下文章一般抄!
Ibatis 批量添加修改删除-batch-insert-update-delete
今天在做一个ssh整合小测试,在测试时出现许多错,好在是这些错误都通过网上的查找解决,得感谢网上的网友慷慨的给大家分享!
既然有错误就和大家一起分享,希望在别人学习的时候不会在碰到这种错误,当然了有哪些不足的地方还请大家多多指正.
1 SSH整合所需的包
注:Spring使用的是spring2.5.5版本
hibernate是hibernate3.3.2
struts是 struts2.1.6
我的数据库用的是mysql的所以在做测试时得需要开一个mysql服务系,具体的包如下图
以上的SSH包就是项目所需的包,其中struts2-codebehind-plugin-2.1.6.jar请大家注意,这个包加上会在项目启动时报第一个错如下
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.1.xsd"> <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/test" /> <property name="username" value="root" /> <property name="password" value="" /> <property name="initialSize" value="5" /> <property name="maxActive" value="20" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="datasource" /> <property name="mappingResources" > <list> <value>model/TProductInfo.hbm.xml</value> <value>model/TProductSubsumption.hbm.xml</value> <value>model/TPurchasingProgramBasicInfo.hbm.xml</value> <value>model/TPurchasingProgramDetailedInfo.hbm.xml</value> <value>model/TRequisitionBasicInfo.hbm.xml</value> <value>model/TRequisitionDetailedInfo.hbm.xml</value> <value>model/TSupplierAgioInfo.hbm.xml</value> <value>model/User.hbm.xml</value> <value>model/TSupplierBasicInfo.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5InnoDBDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <bean id="hibernateTemple" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="userDaoImpl" class="impl.UserDaoImpl"> <property name="hibernateTemplate" ref="hibernateTemple" /> </bean> <bean id="serverce" class="serverce.Proccess"> <property name="dao" ref="userDaoImpl"></property> </bean> <bean id="adduserAction" class="actions.AddUserAction" scope="request"> <property name="serverce" ref="serverce"></property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="daoTransAdvice"> <tx:attributes> <tx:method name="save" isolation="DEFAULT" propagation="REQUIRED"/> <tx:method name="delete" isolation="DEFAULT" propagation="REQUIRED" /> <tx:method name="update" isolation="DEFAULT" propagation="REQUIRED" /> <tx:method name="find*" isolation="DEFAULT" read-only="true" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <tx:advice id="serverceAdvice"> <tx:attributes> <tx:method name="serverce*" isolation="DEFAULT" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* DAO.*.*(..))" id="daoPointcut" /> <aop:pointcut expression="execution(* serverce.*.serverce(..))" id="servercePointcut" /> <aop:advisor advice-ref="daoTransAdvice" pointcut-ref="daoPointcut" /> <aop:advisor advice-ref="serverceAdvice" pointcut-ref="servercePointcut" /> </aop:config> </beans>
2 第一 个错误分析:
错误示例-
我们先看控制台显示的错误:
java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:507)
at com.opensymphony.xwork2.inject.ContainerImpl$8.call(ContainerImpl.java:540)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:538)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:198)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:620)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1233)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo.restartWebApp(AbstractJettyRunMojo.java:441)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo$1.filesChanged(AbstractJettyRunMojo.java:402)
at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:486)
at org.mortbay.util.Scanner.reportDifferences(Scanner.java:352)
at org.mortbay.util.Scanner.scan(Scanner.java:280)
at org.mortbay.util.Scanner$1.run(Scanner.java:232)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:495)
at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:532)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:581)
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:530)
at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
... 27 more
Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:69)
at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:348)
at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:305)
at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:304)
at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
at com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:594)
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:491)
... 32 more
Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:235)
at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:225)
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:287)
at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117)
at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:115)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
... 51 more
2009-03-29 11:23:51.305::WARN: Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@8932e8{/ssh,D:"workplace"ssh"src"main"webapp}
java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:507)
at com.opensymphony.xwork2.inject.ContainerImpl$8.call(ContainerImpl.java:540)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:538)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:198)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:620)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1233)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo.restartWebApp(AbstractJettyRunMojo.java:441)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo$1.filesChanged(AbstractJettyRunMojo.java:402)
at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:486)
at org.mortbay.util.Scanner.reportDifferences(Scanner.java:352)
at org.mortbay.util.Scanner.scan(Scanner.java:280)
at org.mortbay.util.Scanner$1.run(Scanner.java:232)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:495)
at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:532)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:581)
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:530)
at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
... 27 more
Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:69)
at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:348)
at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:305)
at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:304)
at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
at com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:594)
at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:491)
... 32 more
Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:235)
[INFO] Restart completed at Sun Mar 29 11:23:51 CST 2009
at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:225)
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:287)
at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117)
at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:115)
at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
... 51 more
这个错误是因为我们多加了一个包,我们把struts2-codebehind-plugin-2.1.6.jar去掉就好了
关于struts2-codebehind-plugin包的介绍请大家连接——http://www.iteye.com/topic/155425
这个博客有详细的讲解,这个包主要就是解决struts零配置的问题,需要注意的是,在做零配置时,需要建actionPackages时一定要有action的后缀或前缀,如:xxactions;
若是在这个包的类不想继承ActionSupport,必须的在类名的后缀上加上“Action”
3 第二个错误分析
错误示例:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoTransAdvice': 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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
从上面的报的异常可以看出是我们事件管理器出错了,说的是用了错误的命名,我们查看下applicationcontext.xml有关事件管理器的配置:
<bean id="tran" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>
我们把上面的这段配置改为:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>
这样就解决了!
4 第三个错误
错误示例:
这个错误是在我们访问时在浏览器上报的错误如下:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition. org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1182) org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:692) org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419) org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690) impl.UserDaoImpl.save(UserDaoImpl.java:13) serverce.Proccess.serverce(Proccess.java:21) actions.AddUserAction.execute(AddUserAction.java:31) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
web.xml--1
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>lazyload</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>lazyload</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
web.xml--2
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>lazyload</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>lazyload</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern>
从上可以看出我们直接修改OpenSessionInViewFilter过滤器的配置,配置过滤器的时候配置时候直接指定flushMode, 在web.xml文件中添加如下代码:
<filter> <filter-name>lazyload</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter>
问题就会迎刃而解了,也就选用我们的配置2。
3 第四个错误分析
错误示例:
我们在访问某个资源时有以下错误输出:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adduserAction': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881) at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:204) at org.apache.struts2.components.ServletUrlRenderer.renderFormUrl(ServletUrlRenderer.java:145) at org.apache.struts2.components.Form.populateComponentHtmlId(Form.java:228) at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:784) at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:57)
分析:
从上可以看出我们的说的是我们的bean作用域错误,
我们的spring 的bean一般默认作用域为:
作用域将对Bean的生命周期和创建方式产生影响.
singleton 在spring IOC容器中仅存在一个Bean实例,Bean以单实例的方式存在.
prototype 每次从容器中调用Bean时,都返回一个新的实例,即每次调用getBean()
时,相当于执行new XxxBean()的操作.
request 每次HTTP请求都会创建一个新的Bean,该作用域仅适用于
webApplicationContext环境.
session 同一个HTTP session共享一个Bean,不同HTTP session使用不同的Bean
,该作用域仅适用于webApplicationContext环境.
globalSession 同一个全局session共享一个Bean,一般用于portlet应用环境,该作用域
仅适用于webApplicationContext环境.
在低版本的spring中,由于只有两个Bean作用域,所以采用singleton="true|false"的配置方式,spring2.0
为了向后兼容,依旧支持这种配置方式.不过,spring2.0推荐采用新的配置方式:scope="<作用域类型>"
问题: 查看了applicationcotext.xml配置发现
</bean> <bean id="adduserAction" class="actions.AddUserAction" scope="request"> <property name="serverce" ref="serverce"></property> </bean>
在这个bean中作用域是“request”,着说明 我们得扩展我们的作用域,负责就找不到,而扩展作用域是在“RequestContextListener”的这个类中做的,确切的说他是个listener,一般listener是需要在web.xml中配置的,看来是没有配置这个listener,我们来查看web.xml
解决办法: 果然是没有配置上“RequestContextListener”,问题找到了,我们只需在web.xml上加上如下图
<listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
加上这个listener后就把作用域的问题解决了!
以上只是我所遇到的常见问题,当然了不止这么多,我只是把主要的剪出来,有什么不对的地方还请大家多指教,同时大家若是还遇到别的问题时,也可以拿来一起分享解决!
相关推荐
在IT行业中,SSH整合指的是Spring、Struts和Hibernate这三个开源框架的集成,它们共同构建了一个强大的企业级Web应用开发解决方案。然而,在实际操作过程中,开发者经常会遇到各种问题,其中之一就是...
这个过程通常涉及到几个关键步骤,包括配置SSH免密登录和编写能够跨主机执行命令的shell脚本。 首先,让我们详细解释SSH免密登录。默认情况下,每次通过SSH连接到远程主机时,都需要输入密码。为了实现无密码登录,...
在这个练习中,我们可能会涉及到以下几个核心知识点: 1. SSH基础知识:SSH提供了一种加密的网络通信方式,常用于替代传统的telnet等明文传输协议,以保护数据的安全性。它通过公钥基础设施(PKI)进行身份验证,...
4. **最佳实践分享**:提供一些实际项目中常见的问题解决方案,例如如何优化性能、避免常见错误等。 5. **案例分析**:通过具体的案例来展示如何运用SSH框架完成一个完整的项目。 #### 三、项目资料详解 项目资料...
在SSH项目测试题中,可能涵盖了以下几个关键知识点: 1. **SSH协议原理**:了解SSH如何通过加密技术建立安全通道,以及它如何替代不安全的Telnet协议。SSH使用公钥/私钥对进行身份验证,并且在整个会话中加密数据,...
它的工作原理可以分为几个关键步骤: 1. **密钥交换**:SSH使用非对称加密技术进行密钥交换。客户端和服务器在连接时会协商一个共享的秘密,这个过程涉及到公钥和私钥的交换,确保只有拥有正确私钥的用户才能解密...
为了深入理解SSH框架整合,你需要关注以下几个关键点: 1. **Struts2配置**:理解struts.xml文件中的Action配置,包括Action的命名、结果映射、拦截器链等。 2. **Spring配置**:解析applicationContext.xml中的...
为了优化Hibernate,需要遵循以下几个原则: * 使用双向一对多关联,不使用单向一对多 * 灵活使用单向一对多关联 * 不用一对一,用多对一取代 * 配置对象缓存,不使用集合缓存 * 一对多集合使用Bag,多对多集合使用...
下面将详细解释SSH的原理、配置过程以及可能遇到的常见错误,以帮助解决这个问题。 SSH主要通过加密技术确保数据传输的安全性,它支持命令行交互、文件传输以及远程执行命令等功能。在Linux或Unix系统中,SSH通常...
在深入分析这个项目时,我们可以关注以下几个关键知识点: 1. **Struts框架**:学习Struts的Action、配置文件、拦截器等概念,以及如何处理HTTP请求和转发到相应的视图。 2. **Spring框架**:了解依赖注入(DI)和...
SSH安装失败通常由以下几个方面的原因引起: 1. **网络问题**:网络连接不稳定或存在限制,导致无法从Ubuntu仓库下载SSH相关软件包。 2. **依赖缺失**:安装SSH时所需的依赖库未安装完整,导致安装过程出现问题。 3...
SSH登录过程主要涉及以下几个关键知识点: 1. **公钥与私钥认证**:SSH支持多种身份验证方式,其中最安全的是基于密钥对的认证。每个用户有一对密钥,公钥存放在远程服务器,私钥保留在本地客户端。当用户尝试登录...
用户管理系统的核心组件可能包括以下几个部分: 1. **用户模型**:这是系统中表示用户信息的数据结构,通常包含用户名、密码(加密存储)、权限级别等字段。 2. **身份验证模块**:该模块负责处理用户登录请求,...
配置“publish-over-ssh”插件主要包括以下几个步骤: 1. **创建SSH凭据**:在“管理Jenkins” -> “管理凭据”中,添加新的SSH密钥或用户名/密码组合,用于连接远程服务器。确保拥有足够的权限来执行部署操作。 2...
- **错误排查**: 如果配置完成后仍然无法实现免密码登录,可以检查以下几个方面: - 确保目标服务器上的`.ssh`目录权限正确设置,通常应为700。 - `authorized_keys`文件的权限应为600。 - 检查`/etc/ssh/sshd_...
这个案例通常会包含以下几个部分: 1. **Struts2配置**:定义Action类和对应的URL映射,设置结果视图,以及可能使用的拦截器。 2. **Hibernate配置**:配置数据源、实体类映射文件、SessionFactory的创建等,实现对...
常见的目录结构可能包括以下几个部分: - `src/main/java`:存放Java源代码,按照Maven或者Gradle的标准目录结构,通常会分为model、service、dao、controller等包,分别对应业务模型、服务层、数据访问层和控制器...
6. **错误处理和调试**:学习如何处理SSH连接失败、权限问题等常见错误,并了解如何调试SSH相关的代码问题。 7. **文档和示例**:尽管描述中没有提供,但理想的SSH框架代码应附带详细文档和示例,帮助用户快速上手...
【SSH框架优化】主要包括以下几个方面: 1. **属性文件配置数据源**: 在SSH框架中,使用属性文件配置数据源能有效地管理数据库连接信息。首先,你需要将属性文件(如`jdbc.properties`)拷贝到项目中,并修改其中...
在 Ubuntu 系统中, SSH 服务的配置是一个非常重要的步骤,特别是在 Windows 下进行 Linux 开发时。下面将详细介绍 Ubuntu 中 SSH 服务的配置过程。 首先,在 Ubuntu 系统中,需要安装 openssh-server 软件包,以便...