Sprigmvc项目转为springboot的方法

  

是否有老掉牙的springmvc项目,想转成springboot项目,看这个文章就对了。

  

<强>说明

  

如果你的项目连maven项目都不是,请自行转为maven项目,在按照本教程进行。
  

  

本教程适用于弹簧+ springmvc + mybatis + shiro的maven项目。
  

  

<强> 1。修改pom文件依赖

  

删除之前的春天依赖,添加springboot依赖

        & lt; parent>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-parent   & lt; version> 1.5.9.RELEASE   & lt;/parent>   & lt; dependencies>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter   & lt;/dependency>      & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-test   & lt; scope> test   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-web      & lt; !——这个是剔除掉自带的tomcat部署的——比;   & lt; exclusions>   & lt; exclusion>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-tomcat   & lt;/exclusion>   & lt;/exclusions>      & lt;/dependency>   & lt; !- - - tomcat容器部署——比;   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-tomcat   & lt; !——& lt; scope> compile——比;   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.mybatis.spring.boot   & lt; artifactId> mybatis-spring-boot-starter   & lt; version> 1.3.0   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-devtools   & lt; optional> true   & lt;/dependency>   & lt; !——支持@ConfigurationProperties注解——比;   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-configuration-processor   & lt; optional> true   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.apache.tomcat.embed   & lt; artifactId> tomcat-embed-jasper   & lt;/dependency>   & lt;/dependencies>      之前      

<强>添加springboot构建插件

        & lt; plugins>   & lt; plugin>   & lt; groupId> org.apache.maven.plugins   & lt; artifactId> maven-compiler-plugin   & lt; configuration>   & lt; source> 1.7 & lt;/source>   & lt; target> 1.7 & lt;/target>   & lt;/configuration>   & lt;/plugin>   & lt; plugin>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-maven-plugin   & lt; version> 1.5.9.RELEASE   & lt; executions>   & lt; execution>   & lt; goals>   & lt; goal> repackage   & lt;/goals>   & lt;/execution>   & lt;/executions>   & lt;/plugin>   & lt;/plugins>   之前      

<强> 2。添加应用程序启动文件

  

注意,如果在控制器,应用服务,刀的上一层包里,无需配置@ComponentScan,

  

否,则需要指明要扫描的包。

        @SpringBootApplication//@ComponentScan ({“com.cms.controller”、“com.cms.service”、“com.cms.dao”})   公开课Applicationextends SpringBootServletInitializer {      @Override   保护SpringApplicationBuilder配置(SpringApplicationBuilder应用程序){   返回application.sources (Application.class);   }      公共静态void main (String [] args){抛出异常   SpringApplication.run (Application.class, args);   }   }      之前      

<强> 3。添加springboot配置文件

  

在资源下面添加应用程序。属性文件
  

        添加基本配置   #默认前缀   server.contextPath=/#指定环境   spring.profiles.active=当地   # jsp配置   spring.mvc.view.prefix=/web - inf/jsp/spring.mvc.view.suffix=. jsp   #日志配置文件   logging.config=类路径:logback-cms.xml   #日志路径   logging.path=/用户/mac/work-tommy/cms-springboot/日志/#数据源   spring.datasource.name=adminDataSource   弹簧数据源。driverClassName=com.mysql.jdbc.Driver   弹簧数据源。url=jdbc: mysql://localhost: 3306/mycms& # 63; useUnicode=true& autoReconnect=true& characterEncoding=utf - 8   弹簧数据源。用户名=根   弹簧数据源。密码=123456   

Sprigmvc项目转为springboot的方法