我是 Spring-MVC 和 Hibernate 的新手。尝试使用Spring-MVC(4.0.3)、Hibernate(4.3.5)并使用MySQL作为后端创建一个测试 Web 应用程序。
连接到数据库没有问题,因为我尝试使用简单的 JDBC 连接语句从示例 testJavaClass 中的同一数据库获取数据,并且能够获取记录。
错误日志:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
root cause
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:515)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
com.sun.proxy.$Proxy130.listPersons(Unknown Source)
com.journeldev.spring.PersonController.listPersons(PersonController.java:29)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606) …Run Code Online (Sandbox Code Playgroud) 我的 github 公共存储库中有 spring boot 应用程序。我使用 gradle 作为这个 Spring Boot 应用程序的构建工具。我使用詹金斯作为 CI/CD。
我的 build.gradle 文件中有以下任务,用于自动递增内部版本号,以便生成的可执行 jar 在生成的 jar 文件中具有唯一的版本名称。
task versionIncr {
Properties props = new Properties()
File propsFile = new File('gradle.properties')
props.load(propsFile.newDataInputStream())
Integer nextbuildnum = ( ((props.getProperty('artifactBuildNumber')) as BigDecimal) + 1 )
props.setProperty('artifactBuildNumber', nextbuildnum.toString())
props.store(propsFile.newWriter(), null)
props.load(propsFile.newDataInputStream())
}
Run Code Online (Sandbox Code Playgroud)
我在詹金斯中调用此任务,如下所示。
“versionIncr bootJar docker --warning-mode=all”
这个任务运行得很好。由于以下任务发生在詹金斯服务器中
versionIncr正在执行并增加版本号并更新"gradle.properties"jenkins 服务器中工作区中的文件问题:: 对“”文件所做的更改gradle.properties保留在 jenkins …