joy460154849 2018-11-25 08:06 采纳率: 0%
浏览 1223
已结题

springmvc 注解方式配置时,没有了web.xml,如何内嵌jetty

package config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan( "com")
public class WebConfig extends WebMvcConfigurerAdapter{

/**
 *配置静态资源处理 
 *
 */
public void configureDefaultServerletHandling(DefaultServletHandlerConfigurer configurer){
    configurer.enable();
}

/**
 *配置视图解析器 
 */
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setTemplateLoaderPath("/WEB-INF/");
    return configurer;
}

@Bean
public FreeMarkerViewResolver freeMarkerViewResover(){
    FreeMarkerViewResolver freeMarker = new FreeMarkerViewResolver();
    freeMarker.setSuffix(".ftl");
    freeMarker.setContentType("utf-8");
    return freeMarker;
}

/**
 * 配置multipart解析器
 */
@Bean
public MultipartResolver multipartResolver(){
    return new StandardServletMultipartResolver();
}

}


package config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@ComponentScan(excludeFilters={@Filter(type=FilterType.ANNOTATION,value=EnableWebMvc.class)})
public interface RootConfig {

}


package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ControllerDemo {

@RequestMapping("/demo/list")
public String demo(Model model){
    model.addAttribute("welcom", "welcom to use spring demo");
    return "demo/index";
}

}


  • 写回答

2条回答 默认 最新

  • 欧阳惜竹 2018-11-25 08:24
    关注

    在项目的跟目录执行mvn clean jetty:run 运行项目
    详情请参考https://blog.csdn.net/mn960mn/article/details/60465951

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?