引入jar包

先不删除老的jar包

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5..RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
  <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- log4j -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <!-- 这个是剔除掉自带的 tomcat部署的-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions> </dependency>
<!-- tomcat容器部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>compile</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- 支持 @ConfigurationProperties 注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

spring boot打包的插件

  <build>
<finalName>MIS</finalName>
<!-- maven 打包不全(xml,properties文件没打进包)解决方案-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5..RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

创建springboot主类

package com.guige;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan; @SpringBootApplication
@ComponentScan({"com.guige.oim.v2.*"})
public class Application extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
} public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}

创建application.properties文件

#默认前缀
server.contextPath=/ #数据源
spring.datasource.name=adminDataSource
spring.datasource.driverClassName = oracle.jdbc.OracleDriver
spring.datasource.url =
spring.datasource.username =
spring.datasource.password =

1.先把web.xml去掉

创建core包

web.xml里的servlet转成bean形式

filter也一样

创建WebConfig配置类

package com.guige.core.conf;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.guige.core.ext.i18n.filter.LocaleFilter;
import com.guige.mis.filter.JspFilter;
import com.guige.mis.listener.ContextListener;
import com.guige.mis.listener.OnlineUserListener;
import com.guige.oim.filter.CORSFilter;
import com.guige.oim.servlet.*;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet; /**
* 对应web.xml
*
* @author songaw
* @date 2018/7/17 9:10
*/
@Configuration
public class WebConfig {
//----------------------Filter
//跨域过滤器
@Bean
public FilterRegistrationBean corsRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new CORSFilter());
filterRegistrationBean.addUrlPatterns("/*");
return filterRegistrationBean;
}
//字符集utf-8
@Bean
public FilterRegistrationBean characterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
filterRegistrationBean.setFilter(characterEncodingFilter);
filterRegistrationBean.addUrlPatterns("/*");
//filterRegistrationBean.addInitParameter("encoding", "UTF-8");
// filterRegistrationBean.addInitParameter("ForceEncoding", "true");
return filterRegistrationBean;
}
//对jsp进行权限日志过滤
@Bean
public FilterRegistrationBean jspFilterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
JspFilter jspFilter = new JspFilter();
filterRegistrationBean.setFilter(jspFilter);
filterRegistrationBean.addUrlPatterns("*.do");
return filterRegistrationBean;
} /**
* 如果session中没有设置locale串或者locale串不合法,默认采用request的locale,
* @return
*/
@Bean
public FilterRegistrationBean localeRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new LocaleFilter());
filterRegistrationBean.addUrlPatterns("*.do");
return filterRegistrationBean;
}
//阿里druid界面设置
@Bean
public FilterRegistrationBean webStatFilterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
} //--------------------------------Listener @Bean
public ServletListenerRegistrationBean<OnlineUserListener> onlineUserListenerRegistrationBean(){
ServletListenerRegistrationBean<OnlineUserListener>
sessionListener = new ServletListenerRegistrationBean<OnlineUserListener>(new OnlineUserListener());
return sessionListener; }
@Bean
public ServletListenerRegistrationBean<ContextListener> contextListenerRegistrationBean(){
ServletListenerRegistrationBean<ContextListener>
sessionListener = new ServletListenerRegistrationBean<ContextListener>(new ContextListener());
return sessionListener; }
// --------------------------------------Servlet @Bean
public ServletRegistrationBean dispatcher() { ServletRegistrationBean reg = new ServletRegistrationBean();
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation("classpath:config/core/spring-mvc.xml," +
" classpath:config/core/dao/dao_authority.xml," +
" classpath:config/core/dao/dao_manager.xml," +
" classpath:config/core/dao/dao_oim.xml," +
" classpath:config/core/dao/dao_oim_v2.xml," +
" classpath:config/core/dao/dao_orgacus.xml," +
" classpath:config/core/service/service_authority.xml," +
" classpath:config/core/service/service_manager.xml," +
" classpath:config/core/service/service_oim.xml," +
" classpath:config/core/service/service_oim_v2.xml," +
" classpath:config/core/service/service_orgacus.xml," +
" classpath:config/client/i18n.xml," +
" classpath:config/client/http.xml," +
" classpath:config/client/action/action_main.xml," +
" classpath:config/client/action/action_authority.xml," +
" classpath:config/client/action/action_manager.xml," +
" classpath:config/client/action/action_oim.xml," +
" classpath:config/client/action/action_oim_v2.xml," +
" classpath:config/client/action/action_orgacus.xml");
reg.setServlet(dispatcherServlet);
reg.addUrlMappings("*.do");
reg.setLoadOnStartup();
return reg;
} //阿里druid界面设置
@Bean
public ServletRegistrationBean statViewServlet() { ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
reg.addInitParameter("loginUsername", "111");
reg.addInitParameter("loginPassword", "111");
return reg;
} }

2.spring mvc文件

里面的bean 转成声明试bean

package com.guige.core.conf;

import com.alibaba.druid.support.http.WebStatFilter;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guige.oim.filter.CORSFilter;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.resource.ContentVersionStrategy;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView; import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; @Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter { /**
* 添加拦截器
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LocaleChangeInterceptor());
// registry.addInterceptor(webInterceptor());
} /**
*
* @param converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//用来忽略json对象传入,反序列化时候属性名称不正确导致序列化失败的bug
MappingJackson2HttpMessageConverter jacksonMessageConverter = new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes =new ArrayList<>();
// 避免IE执行AJAX时,返回JSON出现下载文件
supportedMediaTypes.add(MediaType.TEXT_HTML);
jacksonMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
ObjectMapper mapper = jacksonMessageConverter.getObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
converters.add(jacksonMessageConverter);
} @Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.viewResolver(this.getViewResolver());
//MappingJsonView jsonView = new MappingJsonView();
// registry.enableContentNegotiation(jsonView);
} @Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setOrder();
return resolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry){
registry.addViewController("/").setViewName("forward:/login.html");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
VersionResourceResolver versionResourceResolver = new VersionResourceResolver();
versionResourceResolver.addVersionStrategy(new ContentVersionStrategy(), "/**");
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.resourceChain(true)
.addResolver(versionResourceResolver);
} @Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setSessionTimeout(, TimeUnit.SECONDS);
ErrorPage ep1 = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
return factory;
} }

3. spring.xml转配置文件

spring老项目转springboot项目 笔记的更多相关文章

  1. docker 运行jenkins及vue项目与springboot项目(三.jenkins的使用及自动打包vue项目)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  2. docker 运行jenkins及vue项目与springboot项目(一.安装docker)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  3. docker 运行jenkins及vue项目与springboot项目(二.docker运行jenkins为自动打包运行做准备)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  4. docker 运行jenkins及vue项目与springboot项目(四.docker运行nginx)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  5. docker 运行jenkins及vue项目与springboot项目(五.jenkins打包springboot服务且在docker中运行)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  6. 怒改springMVC项目为springBoot项目

    背景:公司最近在做项目升级,融合所有项目,但是目前使用的一个系统还是最原始的框架 springMVC+spring+mybatis ,前端还是jsp,easyui(技术老的掉牙),终于出手了,结果.. ...

  7. spring boot学习(2) SpringBoot 项目属性配置

    第一节:项目内置属性 application.properties配置整个项目的,相当于以前的web.xml: 注意到上一节的访问HelloWorld时,项目路径也没有加:直接是http://loca ...

  8. 通过start.spring.io生成的springboot项目,导入IDE后POM第一行报错

    通过problem控制台查看,显示unknown 尝试降低springboot版本,问题没了,应该是与maven jdk等版本冲突导致 这里JDK 1.8  mave 3.6.1  降低springb ...

  9. maven项目或者SpringBoot项目启动时报错在本地仓库中找不到jar包的解决办法

    经常遇到项目检出来后是导入开发工具eclipse中pom文件出错问题,项目启动时遇到了一些列的jar包找不到的问题,所以换个开发平台到IDEA以为会好些,结果同样的问题还是会出现的,为了找到具体的解决 ...

随机推荐

  1. struts 防止重复提交表单

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC     &qu ...

  2. Wireshark-配合tcpdump对Android(安卓)手机抓包

    环境:Windows, 安装真机(可以获取Root权限), adb, Wireshark, tcpdump 原理: 使用 tcpdump 进行抓包, 然后用 Wireshark 进行分析 1.获取手机 ...

  3. Android工程:引用另一个Android工程的方法详解

    本篇文章是对在Android中引用另一个Android工程的方法进行了详细的分析介绍.需要的朋友参考下   现在已经有了一个Android工程A.我们想扩展A的功能,但是不想在A的基础上做开发,于是新 ...

  4. fs 小计

    如果是export 就可以放到b-leg上 如果是set就可以对于a-leg

  5. Xml+Xslt测试工具

    下载地址:http://download.csdn.net/detail/a497785609/5791359 说明:下载后,修改下Xslt部分的头部:<xsl:stylesheet versi ...

  6. 编程算法 - 高速排序算法 代码(C)

    高速排序算法 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 经典的高速排序算法, 作为一个编程者, 不论什么时候都要完整的手写. 代码: /* * m ...

  7. Atitit。Js调用后台语言 java c#  php swing android  swt的方法大总结

    Atitit.Js调用后台语言 java c#  php swing android  swt的方法大总结 1. Js调用后台语言有三种方法1 2. Swt  BrowserFunction 绑定方法 ...

  8. loongson官方PMON使用

    目录 [隐藏]  1 PMON使用介绍 1.1 进入PMON控制界面 1.2 Pmon的图形界面 1.3 Pmon的基本命令 1.3.1 Boot and Load 启动与加载内核 1.3.2 MyC ...

  9. springboot文件上传下载,转载的

    Spring Boot入门——文件上传与下载 原文来自:https://www.cnblogs.com/studyDetail/articles/7003253.html 1.在pom.xml文件中添 ...

  10. 文件上传之 MultipartFile

    利用MultipartFile(组件)实现文件上传 在java中上传文件似乎总有点麻烦,没.net那么简单,记得最开始的时候用smartUpload实现文件上传,最近在工作中使用spring的Mult ...