web source of spring Transformation: mooc.com

Keywords: Spring xml Session Attribute

Preface

We wrote the foundation of spring yesterday, and continue to write the knowledge related to web today

The use of spring web
  1. Import dependency first
<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>

            <artifactId>spring-web</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
  1. Configure the web.xml file
  <servlet>
    <!--servlet Name-->
    <servlet-name>springservlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--spring Location of files-->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:Applaction.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springservlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  1. Write controller
@Controller
public class RequestController {
    
    @ResponseBody
    @RequestMapping("/request")
    public String getrequest(){
        return this.toString();
    }
}
  1. Configure Application.xml file
 <bean id="request" class="RequestController" scope="request"></bean>
    <bean id="session" class="SessionController" scope="session"></bean>
    <bean id="applaction" class="ApplactionController" scope="singleton"></bean>

scope attribute in web:

Lazy loading of Bean

Setting method:

Be careful:
The Spring container will initialize the bean of SigSingleton scope in advance when creating the container. However, the bean is marked with lazy init = true '. The bean will be initialized only when it is needed.

Only valid for singleton scoped bean s
Advantages: save resources as much as possible.
Disadvantage: may cause an operation response time to increase

Bean property inheritance

There are two ways to go in life, one is the way we must go, the other is the way we want to go. We must finish the way we want to go before we can go the way we want to go.

Posted by monarlte on Sat, 30 Nov 2019 22:14:58 -0800