SSH框架入门--启动报错
问题描述
新人学习SSH框架,在博客园找了一个博主的代码,将代码自行复制到工程中,期间出现了很多报错,都自行解决了,就剩下这个操作,实在不知道哪里出现了错误?
启动报错:
There is no Action mapped for namespace [/] and action name [] associated with context path [/demo]
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/7.0.92
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: Nov 9 2018 11:07:44 UTC
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 7.0.92.0
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Windows 7
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 6.1
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture: x86
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home: D:\Java\jdk1.8.0_201\jre
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version: 1.8.0_201-b09
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor: Oracle Corporation
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE: D:\eclipse_work\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME: D:\apache-tomcat-7.0.92
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\eclipse_work\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\apache-tomcat-7.0.92
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\eclipse_work\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-7.0.92\endorsed
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=GBK
四月 18, 2019 2:34:43 下午 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: D:\Java\jdk1.8.0_201\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/Java/jre8/bin/client;D:/Java/jre8/bin;D:/Java/jre8/lib/i386;D:\Oracle\product\11.2.0\dbhome_1\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\OpenCL SDK\2.0\bin\x86;D:\Java\jdk1.8.0_201\bin;;D:\eclipse;;.
四月 18, 2019 2:34:43 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
四月 18, 2019 2:34:43 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
四月 18, 2019 2:34:43 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 720 ms
四月 18, 2019 2:34:43 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
四月 18, 2019 2:34:43 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.92
四月 18, 2019 2:34:44 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [164] milliseconds.
四月 18, 2019 2:34:44 下午 org.apache.catalina.startup.TldConfig execute
信息: 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.
四月 18, 2019 2:34:44 下午 org.apache.catalina.deploy.WebXml setVersion
警告: Unknown version string [3.1]. Default version will be used.
四月 18, 2019 2:34:46 下午 org.apache.catalina.startup.TldConfig execute
信息: 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.
四月 18, 2019 2:34:46 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
四月 18, 2019 2:34:46 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
四月 18, 2019 2:34:46 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization started
四月 18, 2019 2:34:46 下午 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
信息: Refreshing Root WebApplicationContext: startup date [Thu Apr 18 14:34:46 CST 2019]; root of context hierarchy
四月 18, 2019 2:34:46 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
四月 18, 2019 2:34:46 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
四月 18, 2019 2:34:46 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.11.Final}
四月 18, 2019 2:34:46 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
四月 18, 2019 2:34:46 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
四月 18, 2019 2:34:47 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
四月 18, 2019 2:34:47 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
四月 18, 2019 2:34:47 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
四月 18, 2019 2:34:47 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
四月 18, 2019 2:34:47 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
四月 18, 2019 2:34:47 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
四月 18, 2019 2:34:47 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
四月 18, 2019 2:34:48 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
四月 18, 2019 2:34:57 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: ADMIN.MEMBER
四月 18, 2019 2:34:57 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [password, address, name, leve, id, email]
四月 18, 2019 2:34:57 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
四月 18, 2019 2:34:57 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: []
四月 18, 2019 2:34:57 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
四月 18, 2019 2:34:57 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization completed in 10828 ms
四月 18, 2019 2:34:57 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
信息: Parsing configuration file [struts-default.xml]
四月 18, 2019 2:34:57 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
信息: Parsing configuration file [struts-plugin.xml]
四月 18, 2019 2:34:57 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
信息: Parsing configuration file [struts.xml]
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ActionFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ResultFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ConverterFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.factory.InterceptorFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ValidatorFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
四月 18, 2019 2:34:57 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
四月 18, 2019 2:34:57 下午 org.apache.struts2.spring.StrutsSpringObjectFactory info
信息: Initializing Struts-Spring integration...
四月 18, 2019 2:34:57 下午 com.opensymphony.xwork2.spring.SpringObjectFactory info
信息: Setting autowire strategy to name
四月 18, 2019 2:34:57 下午 org.apache.struts2.spring.StrutsSpringObjectFactory info
信息: ... initialized Struts-Spring integration successfully
四月 18, 2019 2:34:58 下午 org.apache.catalina.startup.TldConfig execute
信息: 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.
四月 18, 2019 2:34:58 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
四月 18, 2019 2:34:58 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
四月 18, 2019 2:34:58 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 14497 ms
四月 18, 2019 2:34:58 下午 org.apache.struts2.dispatcher.Dispatcher error
严重: Could not find action or result
/demo/
There is no Action mapped for namespace [/] and action name [] associated with context path [/demo]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
问题出现的环境背景及自己尝试过哪些方法
按照网上各种方法,检查了web.xml,struts.xml,applicationContext.xml等配置文件,没有看出问题,请各位大神,帮忙掌掌眼。
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>demo</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring"></constant>
<package name="default" namespace="/" extends="struts-default">
<!-- class属性值是spring定义的Bean,当执行execute()返回success时,控制转到另一个动作memberQuery -->
<action name="memberRegister" class="memberRegisterAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
<action name="memberLogin" class="memberLoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/register.jsp</result>
</action>
<action name="memberQuery" class="memberQueryAction">
<result name="success">/displayAll.jsp</result>
</action>
<action name="memberDelete" class="memberDeleteAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
<action name="memberShow" class="memberUpdateAction" method="showMember">
<result name="success">/update.jsp</result>
</action>
<action name="memberUpdate" class="memberUpdateAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
</package>
</struts>
<!-- <struts>
<constant name="struts.devMode" value="true" />
spring托管将Struts2中的Action的实例化工作交由Spring容器统一管理,同时使Struts2中的Action实例能够访问Spring提供的业务逻辑资源,spring容器
依赖注入的优势也可以体现,Struts2提供的spring插件struts2-spring-plugin-2.3.16.3.jar配合 <constant
name="struts.objectFactory" value="spring">使得Struts2的action由Spring来负责进行实例化
<constant name="struts.objectFactory" value="spring"></constant>
<package name="default" namespace="/" extends="struts-default">
class属性值是spring定义的Bean,当执行execute()返回success时,控制转到另一个动作memberQuery
<action name="memberRegister" class="MemberRegisterAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
<action name="memberLogin" class="MemberLoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/register.jsp</result>
</action>
<action name="memberQuery" class="MemberQueryAction">
<result name="success">/displayAll.jsp</result>
</action>
<action name="memberDelete" class="MemberDeleteAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
<action name="memberShow" class="MemberUpdateAction"
method="showMember">
<result name="success">/update.jsp</result>
</action>
<action name="memberUpdate" class="MemberUpdateAction">
<result name="success" type="redirectAction">/memberQuery</result>
</action>
</package>
</struts> -->
applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- spring 框架提供了多种数据源类,可以使用spring提供的DriverManagerDataSource类还可以使用第三方数据源,
如C3P0的ComboPooledDataSource数据源类,注意相应的两个jar包c3p0-0.9.2.1.jar mchange-commons-java-0.2.3.4.jar -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)(SERVER=DEDICATED)))" />
<property name="username" value="admin" />
<property name="password" value="admin" />
<!-- <property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="2" />
<property name="maxIdleTime" value="20" /> -->
</bean>
<!-- Hibernate4已经完全实现自己的事物管理,所以spring4不提供HibernateDaoSupport和HibernateTemplete的支持
可以在应用程序的spring上下文中,像配置其他bean那样来配置HibernateSession工厂。 如果要使用XML文件定义对象与数据库之间的映射,则需要在spring中配置LocalSessionFactoryBean。
hibernateProperties属性配置了Hibernate如何进行操作的细节。 "hibernate.current_session_context_class"是为当前Session提供一个策略,
Session由org.springframework.orm.hibernate4.SpringSessionContext.currentSession得到。
将sessionFactory注入到其他Bean中,如注入到DAO组件中,使其获得SessionFactory的引用后,就可以实现对数据库的访问。 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/entity/Member.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
<prop key="hibernate.current_session_context_class">
org.springframework.orm.hibernate4.SpringSessionContext
</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="memberDao" class="com.dao.MemberDAOImpl">
<!-- 构造方法注入会话工厂组件sessionFactory -->
<constructor-arg>
<ref bean="sessionFactory" />
</constructor-arg>
</bean>
<bean id="memberService" class="com.service.MemberServiceImpl">
<!-- 设值注入DAO组件 -->
<property name="memberDao" ref="memberDao"></property>
</bean>
<bean id="memberRegisterAction"
class="com.action.MemberRegisterAction">
<!-- 设值注入业务逻辑组件 -->
<property name="memberService" ref="memberService"></property>
</bean>
<bean id="memberLoginAction" class="com.action.MemberLoginAction">
<property name="memberService" ref="memberService"></property>
</bean>
<bean id="memberQueryAction" class="com.action.MemberQueryAction">
<property name="memberService" ref="memberService"></property>
</bean>
<bean id="memberDeleteAction"
class="com.action.MemberDeleteAction">
<property name="memberService" ref="memberService"></property>
</bean>
<bean id="memberUpdateAction"
class="com.action.MemberUpdateAction">
<property name="memberService" ref="memberService"></property>
</bean>
</beans>
工程截图
你期待的结果是什么?实际看到的错误信息又是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
别用这个框架了,太老了,用springboot,几行代码的事