SpringBoot环境

  1. 添加依赖
    <!-- Spring MVC -->
    <dependency>
    	<groupId>org.anyline</groupId>
    	<artifactId>anyboot-mvc</artifactId>
    	<version>${anyboot.version}</version>
    </dependency>
    
    <!-- MySQL 根据实际情况 -->
    <dependency>
    	<groupId>org.anyline</groupId>
    	<artifactId>anyboot-jdbc-mysql</artifactId>
    	<version>${anyboot.version}</version>
    </dependency>

    实际开始项目一般会有一个*-parent.xml的pom来维护版本号,为了方便搭建环境提供几个常用的依赖

    <!--集成springmvc -->
    <parent>
    	<groupId>org.anyboot</groupId>
    	<artifactId>anyboot-start-mvc</artifactId>
    	<version>8.3.7.215-SNAPSHOT</version>
    </parent>
    
    <!--集成在anyboot-start-mvc基础上添加JSP环境-->
    <parent>
    	<groupId>org.anyboot</groupId>
    	<artifactId>anyboot-start-mvc-jsp</artifactId>
    	<version>8.3.7.215-SNAPSHOT</version>
    </parent>
    
    <!--集成在anyboot-start-mvc-jsp基础上添加mysql 前后端不分离的项目经常用这个-->
    <parent>
    	<groupId>org.anyboot</groupId>
    	<artifactId>anyboot-start-mvc-jsp-mysql</artifactId>
    	<version>8.3.7.215-SNAPSHOT</version>
    </parent>
    
    <!--集成在anyboot-start-mvc基础上添加mysql 前后端分离的项目一般用这个-->
    <parent>
    	<groupId>org.anyboot</groupId>
    	<artifactId>anyboot-start-mvc-mysql</artifactId>
    	<version>8.3.7.215-SNAPSHOT</version>
    </parent>


  2. 配置数据源

    默认数据源配置

    spring.datasource.driver=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://127.0.0.1:36902/al_api?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
    spring.datasource.username=root
    spring.datasource.password=root


    如果需要操作多数据源,添加以下配置

    spring.datasource.list=sso,cms #先定义数据源列表
    #依次配置列表中指定的数据源
    spring.datasource.sso.driver=com.mysql.cj.jdbc.Driver
    spring.datasource.sso.url=jdbc:mysql://127.0.0.1:36902/al_sso?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
    spring.datasource.sso.username=root
    spring.datasource.sso.password=root
    
    spring.datasource.cms.driver=com.mysql.cj.jdbc.Driver
    spring.datasource.cms.url=jdbc:mysql://127.0.0.1:36902/al_cms?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
    spring.datasource.cms.username=root
    spring.datasource.cms.password=root
    


  3. 配置类中扫描org.anylie与org.anyboot包
    import org.anyboot.config.db.ds.DynamicDataSourceRegister; 
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Import;
    @SpringBootApplication
    @ComponentScan(basePackages = { "org.anyline", "org.anyboot" })
    @Import(DynamicDataSourceRegister.class)
    public class Main {
    	public static void main(String[] args) {
    		SpringApplication.run(Main.class, args);
    	}
    }

其余操作于Srping MVC环境完全一致

其他文档