springboot2.1.3.RELEASE+jsp笔记war部署tomcat

springboot+jsp

1 <packaging>war</packaging> 2 <parent> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-parent</artifactId> 5 <version>2.1.3.RELEASE</version> 6 </parent> 7 <properties> 8 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 9 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 10 </properties> 11 <dependencies> 12 13 <dependency> 14 <groupId>org.springframework.boot</groupId> 15 <artifactId>spring-boot-starter-web</artifactId> 16 <version>2.1.3.RELEASE</version> 17 <exclusions> 18 <exclusion> 19 <groupId>org.springframework.boot</groupId> 20 <artifactId>spring-boot-starter-tomcat</artifactId> 21 </exclusion> 22 </exclusions> 23 </dependency> 24 <!--sql server驱动--> 25 <dependency> 26 <groupId>com.microsoft.sqlserver</groupId> 27 <artifactId>mssql-jdbc</artifactId> 28 <version>6.2.0.jre8</version> 29 <scope>runtime</scope> 30 </dependency> 31 <!--oracle 驱动--> 32 <dependency> 33 <groupId>com.oracle</groupId> 34 <artifactId>ojdbc6</artifactId> 35 <version>12.1.0.1-atlassian-hosted</version> 36 <scope>runtime</scope> 37 </dependency> 38 <!--jdbc--> 39 <dependency> 40 <groupId>org.springframework.boot</groupId> 41 <artifactId>spring-boot-starter-jdbc</artifactId> 42 </dependency> 43 <!--druid 连接池--> 44 <dependency> 45 <groupId>com.alibaba</groupId> 46 <artifactId>druid-spring-boot-starter</artifactId> 47 <version>1.1.10</version> 48 </dependency> 49 <!--mybatis 持久框架--> 50 <dependency> 51 <groupId>org.mybatis.spring.boot</groupId> 52 <artifactId>mybatis-spring-boot-starter</artifactId> 53 <version>1.3.1</version> 54 </dependency> 55 <!--spring测试--> 56 <dependency> 57 <groupId>org.springframework.boot</groupId> 58 <artifactId>spring-boot-starter-test</artifactId> 59 <scope>test</scope> 60 </dependency> 61 <!--用于编译jsp --> 62 <dependency> 63 <groupId>org.apache.tomcat.embed</groupId> 64 <artifactId>tomcat-embed-jasper</artifactId> 65 <scope>provided</scope> 66 </dependency> 67 <!--jstl--> 68 <dependency> 69 <groupId>jstl</groupId> 70 <artifactId>jstl</artifactId> 71 <version>1.2</version> 72 </dependency> 73 <dependency> 74 <groupId>org.springframework.boot</groupId> 75 <artifactId>spring-boot-starter-tomcat</artifactId> 76 <scope>provided</scope> 77 </dependency> 78 </dependencies> 79 <build> 80 <!--打包后的名字--> 81 <finalName>xxx</finalName> 82 <plugins> 83 <plugin> 84 <groupId>org.apache.maven.plugins</groupId> 85 <artifactId>maven-compiler-plugin</artifactId> 86 <configuration> 87 <target>1.8</target> 88 <source>1.8</source> 89 </configuration> 90 </plugin> 91 <plugin> 92 <groupId>org.springframework.boot</groupId> 93 <artifactId>spring-boot-maven-plugin</artifactId> 94 <executions> 95 <execution> 96 <goals> 97 <goal>repackage</goal> 98 </goals> 99 </execution> 100 </executions> 101 </plugin> 102 </plugins> 103 </build>

与普通springboot项目的区别:

1/** 2 * 配置程序入口,用于打war包 3 */ 4public class SpringBootStartApplication extends SpringBootServletInitializer { 5 @Override 6 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 7 return builder.sources(ShuJuApplication.class); 8 } 9} 10

favicon.ico配置:

1 <link rel="icon" type="image/x-icon" href="${pageContext.request.contextPath}/favicon.ico"> 2 <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/x-icon" />

resources/banner.txt定义打印logo

简单配置文件:

1# 端口号 2#server.port=8081 3# 关闭默认favicon.ico 4spring.mvc.favicon.enabled=false 5 6# sqlServer 连接配置 7spring.datasource.type=com.alibaba.druid.pool.DruidDataSource 8spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver 9spring.datasource.jdbcUrl= 10spring.datasource.username= 11spring.datasource.password= 12 13# sqlServer2 连接配置 14spring.datasource2.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver 15spring.datasource2.jdbcUrl= 16spring.datasource2.username= 17spring.datasource2.password= 18 19# oracle2 连接配置 20spring.oracle2.driver-class-name=oracle.jdbc.OracleDriver 21spring.oracle2.jdbcUrl= 22spring.oracle2.username= 23spring.oracle2.password= 24 25# oracle 连接配置 26spring.oracle.driver-class-name=oracle.jdbc.OracleDriver 27spring.oracle.jdbcUrl= 28spring.oracle.username= 29spring.oracle.password= 30 31# 前段文件前缀,后缀 如 return "index"; 会进入 /WEB-INF/view/index.jsp 32spring.mvc.view.prefix=/WEB-INF/view/ 33spring.mvc.view.suffix=.jsp 34 35# druid 连接池相关配置 36spring.datasource.druid.initial-size=5 37spring.datasource.druid.min-idle=5 38spring.datasource.druid.maxActive=20 39spring.datasource.druid.maxWait=60000 40spring.datasource.druid.timeBetweenEvictionRunsMillis=60000 41spring.datasource.druid.minEvictableIdleTimeMillis=300000 42spring.datasource.druid.validationQuery=SELECT 'x' 43spring.datasource.druid.testWhileIdle=true 44spring.datasource.druid.testOnBorrow=false 45spring.datasource.druid.testOnReturn=false 46spring.datasource.druid.poolPreparedStatements=true 47spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20 48 49# 日志输出 50logging.level.xx.dao=debug

多数据源配置:

DataSourceConfig:

1/** 2 * 多数据源DataSource定义 3 */ 4@Configuration 5@PropertySource("file:${user.dir}/src/main/resources/db.properties") 6//@PropertySource("file:${user.dir}/db/db.properties") //生产环境配置文件外放 7public class DataSourceConfig { 8 /** 9 * sqlServer数据源 10 * @return 11 */ 12 @Primary //主要 13 @Bean(name = "sqldata") 14 @ConfigurationProperties(prefix = "spring.datasource") 15 public DataSource sqlServerDataSource(){ 16 return DataSourceBuilder.create().build(); 17 } 18 /** 19 * oracle数据源 20 * @return 21 */ 22 @Bean(name = "oracledata") 23 @ConfigurationProperties(prefix = "spring.oracle") 24 public DataSource oracleDataSource(){ 25 return DataSourceBuilder.create().build(); 26 } 27}

SqlServerDbConfig:

1/** 2 * 使用sql数据源配置 3 */ 4@Configuration 5@MapperScan(basePackages = {"xxx.dao"},sqlSessionFactoryRef ="sqlSqlSessionFactory" ) // 使用sqlServer数据源的包扫描 6public class SqlServerDbConfig { 7 // 引入 DataSourceConfig类下定义的DataSource 8 @Autowired 9 @Qualifier("sqldata") 10 private DataSource sqldata; 11 12 @Bean 13 @Primary 14 public SqlSessionFactory sqlSqlSessionFactory() throws Exception{ 15 SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); 16 factoryBean.setDataSource(sqldata); 17 return factoryBean.getObject(); 18 } 19 @Bean 20 @Primary 21 public SqlSessionTemplate sqlSqlSessionTemplate() throws Exception{ 22 return new SqlSessionTemplate(sqlSqlSessionFactory()); 23 } 24}

OracleServerDbConfig:

1/** 2 * 使用oracle数据源配置 3 */ 4@Configuration 5@MapperScan(basePackages = {"xxx.ordao"},sqlSessionFactoryRef ="oracleSqlSessionFactory" ) 6public class OracleServerDbConfig { 7 // 引入 DataSourceConfig类下定义的DataSource 8 @Autowired 9 @Qualifier("oracledata") 10 private DataSource oracledata; 11 12 @Bean 13 @Primary 14 public SqlSessionFactory oracleSqlSessionFactory() throws Exception{ 15 SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); 16 factoryBean.setDataSource(oracledata); 17 return factoryBean.getObject(); 18 } 19 @Bean 20 @Primary 21 public SqlSessionTemplate oracleSqlSessionTemplate() throws Exception{ 22 return new SqlSessionTemplate(oracleSqlSessionFactory()); 23 } 24}

war包请使用build/buildArtifacts打包,避免tomcat版本问题,使用tomcat8版本

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )