spring boot 配置dbcp2出現只讀

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition.

yml配置:

# 服務器配置
server:
  port: 8080
  session:
    timeout: 30
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
  context-path: /lemon

# spring 數據源配置
spring:
  datasource:
    # 主數據源
    url: jdbc:mysql://localhost:3306/lemon_2?characterEncoding=utf8&useSSL=true
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    # 配置dbcp 連接池屬性
    type: org.apache.commons.dbcp2.BasicDataSource
    dbcp2:
        initial-size: 5
        min-idle: 5
        max-wait-millis: 60000
        max-total: 30
        time-between-eviction-runs-millis: 300000
        validation-query: SELECT 1 FROM DUAL
        test-while-idle: true
        test-on-borrow: false
        test-on-return: false
        pool-prepared-statements: true
        max-open-prepared-statements: 20
        default-read-only: false


  # jpa 配置
  jpa:
    database: mysql
    show-sql: true
    generate-ddl: true
    hibernate:
      ddl-auto: update
      naming:
        strategy: org.hibernate.cfg.ImprovedNamingStrategy
#      connection:
#      provider_class: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider

  # springMVC 配置
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp

  # 編碼設置
  http:
    encoding:
      force: true
      charset: UTF-8
      enabled: true

#  aop:
#    proxy-target-class: true
# 日誌配置文件地址

#logging:
#  config: classpath:properties/logback-spring.xml


gradle導包:

apply plugin: ‘war’
apply plugin: ‘java’
apply plugin: ‘idea’
apply plugin: ‘org.springframework.boot’

buildscript {
ext {
springBootVersion = ‘1.5.9.RELEASE’
}
repositories {
mavenCentral()
}
dependencies {
classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)
}
}
group = ‘com.lemengxiangju.lemon’
version = ‘0.0.1-SNAPSHOT’
sourceCompatibility = 1.8

repositories {
mavenCentral()
}

//configurations {
// providedRuntime
//}

dependencies {
compile(‘org.springframework.boot:spring-boot-starter-data-jpa’) {
exclude module: ‘org.springframework.boot:spring-boot-starter-logging’
}
compile(‘org.springframework.boot:spring-boot-starter-jdbc’) {
exclude module: ‘org.springframework.boot:spring-boot-starter-logging’
}

compile('org.springframework.boot:spring-boot-starter-web') {
    exclude module: 'org.springframework.boot:spring-boot-starter-logging'
    exclude module: 'org.apache.tomcat:spring-boot-starter-tomcat'
}
compile('mysql:mysql-connector-java')
compile('org.springframework.boot:spring-boot-starter-tomcat')

// jsp 頁面配置
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api

// compile group: ‘javax.servlet’, name: ‘javax.servlet-api’, version: ‘4.0.0’

// https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api

// compile group: ‘javax.servlet.jsp’, name: ‘javax.servlet.jsp-api’, version: ‘2.3.2-b02’

// https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl

// compile group: ‘javax.servlet.jsp.jstl’, name: ‘jstl’, version: ‘1.2’

// 數據庫連接池支持包 dbcp2
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.2.0'


// 配置tomcat jsp 識別。 jsp解析引擎
compile group: 'org.apache.tomcat', name: 'tomcat-jasper', version: '9.0.2'

// alibaba json包
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.44'

// 微信工具dom4j2支持
compile group: 'org.jdom', name: 'jdom2', version: '2.0.6'

// MD5 BASE64 加密依賴jar包
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'


// https://mvnrepository.com/artifact/junit/junit

// testCompile group: ‘junit’, name: ‘junit’, version: ‘4.12’

// swagger API 文檔支持包

// compile group: ‘io.swagger’, name: ‘swagger-annotations’, version: ‘2.0.0-rc2’
compile(“io.springfox:springfox-swagger-ui:2.6.1”)
compile(“io.springfox:springfox-swagger2:2.6.1”)
// compile group: ‘io.swagger’, name: ‘swagger-core’, version: ‘2.0.0-rc2’
// compile group: ‘io.swagger’, name: ‘swagger-parser’, version: ‘2.0.0-rc1’
//

// 加載本地 jar 包
compile fileTree(dir:'libs',include:['*.jar'])

testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')

}

運行出現 上述錯誤 未解決!!!!!!
使用jpa。問題遺留有空看看!!!!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章