zoukankan      html  css  js  c++  java
  • spring mvc改造成spring boot

    一、新增依赖:

             <dependency>

                                <groupId>org.springframework.boot</groupId>

                                <artifactId>spring-boot-dependencies</artifactId>

                                <version>2.0.5.RELEASE</version>

                                <type>pom</type>

                                <scope>import</scope>

                      </dependency>

    二、新建启动类

    @SpringBootApplication

    @PropertySource(value={"*****/config.properties"})

    @MapperScan(basePackages="***")

    @ComponentScan(basePackages={"****"})

    public class StartApplication {

        public static void main(String[] args) {

            SpringApplication.run(***.class, args);

        }

    }

    SpringBootApplication注解=@Configuration + @EnableAutoConfiguration + @ComponentScan

    PropertySource指定加载指定的属性文件

    MapperScan指定要扫描的Mapper类的包的路径,标识持久层mapper接口,用来找到mapper对象

    ComponentScan定义扫描的路径从中找出标识了需要装配的类自动装配到spring的bean容器中,标识业务层的类,用来找到业务层对象

    3、新建SysConfig类继承WebMvcConfigurationSupport

    WebMvcConfigurationSupport是用来全局定制化Spring Boot的MVC特性。如设置拦截器、跨域访问配置、格式化、URI到视图的映射或者其它全局定制接口。

    4、属性文件config.properties配置端口号和上下文

    server.port=7070

    server.servlet.context-path=/**

    5、将xml文件中定义的bean改造成java代码的形式申明注册

    xml文件中定义:

         

    java中定义:

    @Configuration注解可以用java代码的形式实现spring中xml配置文件配置的效果。

    @Configuration

    public class ServiceConfig {

        @Value("${expo.config.path}")

        @Bean(name = "expo4Wrapper")

    }

    6、添加日志配置文件,在src/main/resources下创建logback-spring.xm。

    7、静态资源放在src/main/resources/static下

    8、动态资源放在src/main/resources/templates 下,支持themeleaf、jsp、freemarker等。

    9、@RestController注解相当于@Controller+@ResponseBody两个注解的结合,返回json数据不需要在方法前面加@ResponseBody注解,但使用@RestController这个注解,就不能返回jsp、html页面,视图解析器无法解析jsp、html页面。

    如果需要返回数据到jsp或者html页面,则使用@Controller注解。这里推荐使用@Controller注解,因为需要直接返回数据的时候可以增加@ResponseBody注解

    10、打包,修改web模块下的pom.xml文件,由war包改成jar包

    <packaging>jar</packaging>

    11、将默认的tomcat启动改成jetty启动

    <dependency>

             <groupId>org.springframework.boot</groupId>

             <artifactId>spring-boot-starter-web</artifactId>

             <version>2.0.5.RELEASE</version>

             <exclusions>

                       <exclusion>

                                <groupId>org.springframework.boot</groupId>

                                <artifactId>spring-boot-starter-tomcat</artifactId>

                       </exclusion>

             </exclusions>

    </dependency>

    <dependency>

             <groupId>org.springframework.boot</groupId>

             <artifactId>spring-boot-starter-jetty</artifactId>

             <version>2.0.5.RELEASE</version>

    </dependency>

    12、整合mybatis

    启动类添加@MapperScan(详见1)

    mybatis.typeAliasesPackage=****  一般对应实体类所在的包

    mybatis.mapperLocations=classpath:mapper/*.xml  表示Mapper文件存放的位置

  • 相关阅读:
    SSIS 错误代码 DTS_E_OLEDB_EXCEL_NOT_SUPPORTED 没有可用的 OLE DB 访问接口 SSIS 的 64 位版本中不支持 Excel 连接管理器
    WIN8安装SQL SERVER2008:出现创建userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错的解决办法。
    WIN8安装SQL SERVER2008:出现"MsiGetPRoductInfo” 无法检索 Product Code {47439CBBCF57485B9994BE9E02D29193}的包的 ProductVersion;解决办法。
    解读QT信号与槽机制里 QMetaObject::connectSlotsByName(QObject *o)的源码
    初涉Windows Mobile下的QT程序移植和部署
    C++虚函数探索笔记(1)——虚函数的简单示例分析
    一个不应该发生的BUG。。。
    Qt.Visual.Studio.Integration.1.4.3 与 QT 4.5.0 Commercial for VS2008搭档的一个小问题
    C++ 逗号操作符二三事
    C++虚函数探索笔记(3)——延伸思考:虚函数应用的一些其他情形
  • 原文地址:https://www.cnblogs.com/qcxdoit/p/10382623.html
Copyright © 2011-2022 走看看