• Spring学习日志之纯Java配置的MVC框架搭建


    依赖引入

        <dependencies>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>4.3.12.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.3.12.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>4.3.12.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>4.3.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>8.1.16.v20140903</version>
                </plugin>
            </plugins>
        </build>
    

    三个配置文件

    public class DispatcherServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer
    {
    	@Override
    	protected Class<?>[] getRootConfigClasses()
    	{
    		return new Class<?>[]{BeanConfig.class};
    	}
    
    	@Override
    	protected Class<?>[] getServletConfigClasses()
    	{
    		return new Class<?>[]{WebConfig.class};
    	}
    
    	@Override
    	protected String[] getServletMappings()
    	{
    		return new String[]{"/"};
    	}
    }
    
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackageClasses = {BasePackageMarker.class})
    public class WebConfig extends WebMvcConfigurerAdapter
    {
    }
    
    @Configuration
    public class BeanConfig
    {
    }
    

    测试

    
    @RestController
    public class IndexController
    {
        @GetMapping("/test")
        public String test() {
            return "Hello there.";
        }
    }
    
    
  • 相关阅读:
    (转)使用介质设备安装 AIX 以通过 HMC 安装分区
    (转)在 VMware 中安装 HMC
    (转)50-100台中小规模网站集群搭建实战项目(超实用企业集群)
    (转)awk数组详解及企业实战案例
    (转) IP子网划分
    教你如何迅速秒杀掉:99%的海量数据处理面试题(转)
    PHP对大文件的处理思路
    十道海量数据处理面试题与十个方法大总结
    mysql查询更新时的锁表机制分析
    mysql数据库问答
  • 原文地址:https://www.cnblogs.com/xz816111/p/8379519.html
Copyright © 2020-2023  润新知