我已经将 Spring Boot 项目从 2.2.5 迁移到 2.3.0,之后,验证停止工作(根本没有调用它们)。
我在更改日志文档(https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3.0-M1-Release-Notes)中阅读,spring-boot-starter-validation现在需要手动添加作为依赖项。
所以,我将它添加到我的 pom.xml 中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的 pom 父母是:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath></relativePath>
</parent>
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样:
@PostMapping( value = "/signup", consumes = MediaType.APPLICATION_JSON_VALUE )
@ResponseStatus( value = HttpStatus.OK )
public void signUp( @Valid @RequestBody ClientDto clientDto )
{
onboardingService.signUp( clientDto );
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我找到了问题所在,请查看下面的答案!
感谢大家的帮助!
我在Glassfish 4.1上设置了Hibernate,但是我遇到了持久性问题.我能够读取数据,但无法写入BD(更改似乎没有被提交).
我当前的persistent.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/myDataSource</jta-data-source>
<properties>
<property name="transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
我在Glassfish上的连接池配置是:
<jdbc-connection-pool datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerDataSource" steady-pool-size="2" name="myPool" res-type="javax.sql.DataSource">
<property name="TrustServerCertificate" value="false"></property>
<property name="User" value="sa"></property>
<property name="LastUpdateCount" value="true"></property>
<property name="ResponseBuffering" value="adaptive"></property>
<property name="URL" value="jdbc:sqlserver://server\bd"></property>
<property name="XopenStates" value="false"></property>
<property name="PacketSize" value="8000"></property>
<property name="Password" value="mypass"></property>
<property name="ApplicationName" value="Microsoft JDBC Driver for SQL Server"></property>
<property name="DatabaseName" value="MyDB"></property>
<property name="Encrypt" value="false"></property>
<property …Run Code Online (Sandbox Code Playgroud)