码迷,mamicode.com
首页 > 其他好文 > 详细

注解配置

时间:2020-12-23 12:34:30      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:param   init   ini   pac   指定   startup   xmlns   bean   conf   

<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--    自动扫描包,让指定包下的注解生效,由ioc容器统一管理-->
    <context:component-scan base-package="com.nbg.controller"/>

    <!--    让springmvc不扫描静态资源,例如:.html .jsp .MP3等-->
    <mvc:default-servlet-handler/>

    <!--    让注解生效-->
    <mvc:annotation-driven/>

    <!--    视图解析器-->
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="suffix" value=".jsp"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
    </bean>

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
/**
 * @Controller注解配置的类表示被扫描
 */
@Controller
public class HelloController {
    @RequestMapping("/haha")
    public String one(Model model) {
        model.addAttribute("one", "第一个注解配置的springmvc");
        /**
         * 会被实体解析器处理
         */
        return "one";
    }
}

 

注解配置

标签:param   init   ini   pac   指定   startup   xmlns   bean   conf   

原文地址:https://www.cnblogs.com/NBG-SDL/p/14157323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!