zoukankan      html  css  js  c++  java
  • 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.";
        }
    }
    
    
  • 相关阅读:
    解决WordPress不能发邮件,WordPress 无法发送邮件
    WordPress 显示 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2097160 bytes)解决办法
    怎么优雅的取消重复请求ajax
    手拉手搭建一个脚手架
    数据库隔离级别RC与RR区别——MVCC、ReadView
    整理一下下一步的计划
    减肥
    EBS: Shift + F6: 当复制上行记录
    Oracle 表值函数之多表关联使用
    EBS: 序号授权 GRANT
  • 原文地址:https://www.cnblogs.com/xz816111/p/8379519.html
Copyright © 2011-2022 走看看