How spring is used in Web applications
- Additional JAR packages required
spring-web-4.0.0
spring-webmvc-4.0.0
- Spring configuration file, no different
?
Need to be configured under Web. XML, using myeclipse2014 to automatically generate
? <!-- Start IOC container Servletcontextlin-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</ Listener-class> </listener> ? <!-- Configuration Spring file location- <context-param> <param-name>contextconfiglocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> |
?
After the bean is configured
<body> <% //1. from Application An instance of an IOC container in a domain object ApplicationContext ctx=webapplicationcontextutils.getwebapplicationcontext (application); ? //2. from get bean in IOC container Person P=ctx.getbean. class ); ? //3. Use Bean P.hello (); ? ? %> |
?
?
How to integrate Struts2
Purpose: To enable the IOC container to manage the action of the STRUTS2
?
Configuring STRUTS2 's action in the spring IOC container
Note: When configuring the Struts2 action in the IOC container, the scope property must be configured with a value of prototype
<Beanid="Personservice"class="Com.test.spring_ Web.service.PersonService "></bean> ???? ???? <beanid="Personaction"class="Com.test.spring_ Web.action.PersonAction " ???????? scope="prototype"> ???????? <propertyname="Personservice"ref="Personservice" ></Property> ???? </Bean> |
?
Configure the Struct2 configuration file; The Class property of the action node needs to point to the bean in the IOC container.
<actionname="Person-save"class="personaction"> ???????? <result>/success.jsp</result> ???? </action> |
?
Note the need to add files
?
Spring Notes ⑥--Integration struts2