spring-mvc-3.2.5+servlet-3.1(tomcat8-rc5)+gradle+IntelliJ IDEA 12

喜欢新吗???NO,我只想跟下时势..........

idea13 key:xiejx618/899696950-5TFF3-PCZRH-87DTT-Z7WFU-8Y272


一.创建build.gradle文件和所需目录

vim build.gradle

apply plugin:'war'
targetCompatibility = 1.7
version = '1.0'
repositories{
	mavenCentral()
}
dependencies{
    compile 'org.springframework:spring-webmvc:3.2.5.RELEASE'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
    providedCompile 'org.apache.tomcat:tomcat-servlet-api:8.0.0-RC5'
}
tasks.create(name: 'deploy',dependsOn:'war', type: Copy) {
    from(file("$buildDir/libs/gradletest-1.0.war"))
    into('/Volumes/3/tomcat8/webapps')
}

mkdir -p src/java/main

mkdir -p src/java/webapp

mkdir -p src/java/webapp/WEB-INF

二.导入项目到IntelliJ IDEA 12

三.创建ServletInitializer,MvcConfigurerAdapter,一个Controller,一个jsp

package com.test.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * User: xiejx618
 * Date: 13-11-25
 * Time: 下午2:57
 */
public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{AppConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}


package com.test.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * User: xiejx618
 * Date: 13-11-25
 * Time: 下午1:53
 */
@EnableWebMvc
@Configuration
@ComponentScan(basePackages={"com.test.web"})
public class AppConfig extends WebMvcConfigurerAdapter{
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/img/**").addResourceLocations("/img/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
    }

    @Bean
    public InternalResourceViewResolver getInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
  this is the test.jsp page...
</body>
</html>

四.先启动tomcat 8,跟踪下tomcat输出日志tail -f /Volumes/3/tomcat8/logs/catalina.out ,运行gradle:deploy,如果在IDEA看到BUILD SUCCESSFUL,并且tomcat reload成功(跟踪日志有滚动输出),就可以通过浏览器测试了.这个比maven的 plugin要好,直接copy应该要比上传快吧,也不用依赖manage,配什么权限,当然copy不能直接copy到其它机!!!scp可以么???


没有applicationContext.xml,是不是不习惯,看一下配置增强:http://spring.io/blog/2011/06/10/spring-3-1-m2-configuration-enhancements/

需要的就下载吧:http://download.csdn.net/detail/xiejx618/6608001


另spring mvc3.2.7(基于注解配置)+servlet3.1(jetty)+maven3+eclipse


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值