springboot项目解析和配置

1、项目结构


springboot项目解析和配置_第1张图片



2、主要文件解析

Application.class        该类放在最外层

@EnableConfigurationProperties

@SpringBootApplication

@EnableTransactionManagement // 支持事务

@Import(DynamicDataSourceRegister.class) // 注册动态多数据源

public class Application  extends SpringBootServletInitializer{

public Application() {

            // TODO Auto-generated constructor stub

}

public static void main(String[] args) {

                // TODO Auto-generated method stub

                SpringApplication.run(Application.class, args);

}

}



3、application.properties  资源配置文件,放在resources

logging.config=classpath:logback-ys.xml        #加载log日志

server.port=8004                                               #配置访问端口

ys.username=rfysjk                                            #数据库访问名称

ys.password=123456abc

ys.wsdl2=http://61.183.71.134:8888/hcc/hcc_ws2?wsdl

ys.jdbcurl=jdbc:mysql:///kangkang

ys.jdbcusername=root

ys.jdbcpassword=root


基本配置

server.port=8004

jdbc.ds.url=jdbc:mysql:///demoBoot

jdbc.ds.username=root

jdbc.ds.password=root

jdbc.ds.driver-class-name=com.mysql.jdbc.Driver

#mybatis配置

mybatis.type-aliases-package=com.xe.*.model

mybatis.mapper-locations=classpath:mapper/*.xml

#springmvc视图

spring.mvc.view.prefix=/WEB-INF/pages/

spring.mvc.view.suffix=.jsp



4、jdbc.properties

jdbc.driver = com.mysql.jdbc.Driver

jdbc.url = jdbc:mysql:///kangkang

jdbc.username = root

jdbc.password =root



5、pom文件的主要项

            1.5.3.RELEASE

            5.1.26

            UTF-8

            org.springframework.boot

            spring-boot-starter-parent

            1.5.3.RELEASE

            org.springframework.boot

            spring-boot-dependencies

            ${springboot.version}

            pom

            import

            org.springframework.boot

            spring-boot-starter-web

            ${springboot.version}

//  这一项可以不用配置

            org.springframework.boot

            spring-boot-starter-test

            test

            mysql

            mysql-connector-java

            ${mysql.version}


//如果和mybatis整合添加的依赖

            org.springframework.boot

            spring-boot-starter-tomcat

            provided

            org.springframework.boot

            spring-boot-configuration-processor

            true

            org.springframework.boot

            spring-boot-starter-jdbc

            org.springframework.boot

            spring-boot-starter-aop

#配置mybatis整合

            org.mybatis.spring.boot

            mybatis-spring-boot-starter

            1.2.0

            com.alibaba

            druid

            1.0.11


#spring boot tomcat jsp 支持开启

            org.apache.tomcat.embed

            tomcat-embed-jasper

#servlet支持开启

            javax.servlet

            javax.servlet-api

#jstl 支持开启

            javax.servlet

            jstl


6、主要测试类

@RestController

@RequestMapping("/hello")

public class HelloController {

@RequestMapping

public String hello() {

                return "Hello Spring-Boot";

}


@RequestMapping("/info")

public MapgetInfo(@RequestParam String name) {

                Mapmap = new HashMap<>();

                map.put("name", name);

                if(true){

                        throw new RuntimeException("错误");

                }

                return map;

}

@RequestMapping("/list")

public List> getList() {

        List>  list = new ArrayList<>();

        Map map = null;

        for (int i = 1; i <= 5; i++) {

                    map = new HashMap<>();

                    map.put("name", "Shanhy-" + i);

                    list.add(map);

        }

        return list;

}

你可能感兴趣的:(springboot项目解析和配置)