Browse Source

1.修改数据量连接池未德鲁伊 2.配置跨域,并且是高版本的springboot的配置跨域 allowedOriginPatterns代替allowedOrigins

王苗苗 5 months ago
parent
commit
ce775192b3
4 changed files with 64 additions and 2 deletions
  1. BIN
      .DS_Store
  2. 8 0
      pom.xml
  3. 22 0
      src/main/java/com/xlht/xlhtproject/CorsConfig.java
  4. 34 2
      src/main/resources/application.yml

BIN
.DS_Store


+ 8 - 0
pom.xml

@@ -98,6 +98,14 @@
                 </exclusion>
             </exclusions>
         </dependency>
+
+        <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+            <version>1.2.16</version>
+        </dependency>
+
     </dependencies>
     <dependencyManagement>
         <dependencies>

+ 22 - 0
src/main/java/com/xlht/xlhtproject/CorsConfig.java

@@ -0,0 +1,22 @@
+package com.xlht.xlhtproject;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class CorsConfig implements WebMvcConfigurer {
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 添加映射路径,"/**"表示对所有的路径都进行跨域处理
+        registry.addMapping("/**")
+//                .allowedOrigins("*") // 允许所有域名跨域
+                //新版本springboot 要用下面这个
+                .allowedOriginPatterns("*")
+                .allowedMethods("*") // 允许所有的HTTP方法(GET, POST, PUT, DELETE等)
+                .allowedHeaders("*") // 允许所有的头部
+                .allowCredentials(true) // 允许发送Cookie
+                .maxAge(3600); // 预检请求的缓存时间,单位为秒
+    }
+}

+ 34 - 2
src/main/resources/application.yml

@@ -23,12 +23,44 @@ logging:
     org.springframework: warn
 
 
+#spring:
+#  datasource:
+#    url: jdbc:sqlserver://10.1.100.119:1433;DatabaseName=HS_WEB;encrypt=false;trustServerCertificate=true;
+#    username: sa
+#    password: Abc123456
+#    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+
 spring:
   datasource:
-    url: jdbc:sqlserver://10.1.100.119:1433;DatabaseName=HS_WEB;encrypt=false;trustServerCertificate=true;
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+    url: jdbc:sqlserver://10.1.100.119:1433;DatabaseName=HS_WEB;encrypt=false;trustServerCertificate=true
     username: sa
     password: Abc123456
-    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+    # Druid特有配置
+    druid:
+      initial-size: 5
+      min-idle: 5
+      max-active: 10
+      max-wait: 10000
+      time-between-eviction-runs-millis: 60000
+      min-evictable-idle-time-millis: 300000
+      validation-query: SELECT 1
+      test-while-idle: true
+      test-on-borrow: false
+      test-on-return: false
+      pool-prepared-statements: true
+      max-pool-prepared-statement-per-connection-size: 20
+      filter:
+        stat:
+          enabled: true
+            # 慢SQL记录
+          log-slow-sql: true
+          slow-sql-millis: 1000
+          merge-sql: true
+        wall:
+          config:
+            multi-statement-allow: true
 
 #spring:
 #  datasource: