我有一个指向AWS ELB的子域(test.XXXX.com),它接受HTTP(80)和HTTPS(443)请求.我已为443的HTTPS连接配置了SSL认证.我已经尝试通过更改web.xml和server.xml来在Tomcat级别进行HTTP到HTTPS重定向,如中所述
但问题是我需要一个端点用于AWS ELB运行状况检查,该端点不执行HTTP到HTTPS重定向.我尝试了不同的解决方案但没有成功.我也试过了
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Context</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Context</web-resource-name>
<url-pattern>/XXXXX/XXXXXX.html</url-pattern>
</web-resource-collection>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
我的服务器server.xml具有以下配置
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
<Connector port="443" maxThreads="2000" scheme="https" secure="true" SSLEnabled="true" keystoreFile="/home/XXXXX/XXXXX.keystore"
keystorePass="XXXXX" clientAuth="false" keyAlias="XXXX"
sslProtocol="TLS" protocol="org.apache.coyote.http11.Http11Protocol"/>
Run Code Online (Sandbox Code Playgroud)
但是当尝试通过浏览器访问它时,它会将异常作为ERR_TOO_MANY_REDIRECTS.
如果我使用@InitBinder而不限制它,它可以正常使用@RequestBody来验证我的对象.
@InitBinder
private void initBinder(WebDataBinder binder) {
binder.setValidator(validator);
}
@RequestMapping(method=RequestMethod.POST)
public CustomerQuickRegisterEntity saveNewCustomer(@Valid @RequestBody CustomerQuickRegisterEntity customerEntity,BindingResult result)
{
if(result.hasErrors())
{
return new CustomerQuickRegisterEntity();
}
return customerQuickRegisterRepository.save(customerEntity);
}
Run Code Online (Sandbox Code Playgroud)
但问题是当我通过这样做将其限制为一个对象时,因为@InitBinder("customerEntity")它没有验证对象.所以我搜索了stackoverflow,发现@InitBinding它只适用于带注释的对象@ModelAttribute.然后我的问题是,@RequestBody当我使用它时工作正常,@InitBinder但是当我使用它时效果不好@InitBinder("customerEntity")......为什么会这样呢?是否有任何其他方法来验证与之关联的对象(不是单独的对象的属性)@RequestBody
我已经浏览了https://github.com/spring-projects/spring-boot/issues/424但我的项目结构在 /templates 目录中包含 .html 文件,如下所示
.
|-- java
| `-- com
| `-- projectx
| |-- config
| | |-- Application.java
| | `-- WebXmlInitialiser.java
| |-- controller
| | `-- CustomerQuickRegisterController.java
| |-- domain
| | `-- Email.java
| `-- services
| |-- CustomerQuickRegisterDataFixtures.java
| |-- CustomerQuickRegisterHandler.java
| `-- CustomerQuickRegisterService.java
`-- resources
|-- application.properties
`-- templates
|-- emailForm.html
`-- result.html
Run Code Online (Sandbox Code Playgroud)
但是仍然在使用以下测试进行测试时
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
@ActiveProfiles("Test")
public class CustomerQuickRegisterControllerIntergrationTest {
@Autowired
private WebApplicationContext wac;
MockMvc …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 数据库初始化,使用 Spring JDBC 和 schema.sql 文件。我正在使用 MYSQL
如果我在 schema.sql 中有简单的表创建,如下所示,它可以正常工作
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
Run Code Online (Sandbox Code Playgroud)
但是当我添加一个触发器时,它在 MySQL Workbench 中正确运行
DROP TRIGGER IF EXISTS Persons_log_update;
CREATE TRIGGER Persons_log_update
BEFORE UPDATE ON Persons
FOR EACH ROW
BEGIN
INSERT INTO Personshistory(PersonID,LastName,FirstName,Address,City)
values(OLD.PersonID,OLD.LastName,OLD.FirstName,OLD.Address,OLD.City);
END ^;
Run Code Online (Sandbox Code Playgroud)
我用过 spring.datasource.separator=^; 在此处提到的属性文件中
但它失败了,但有例外
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the …Run Code Online (Sandbox Code Playgroud) 当我们在spring中定义任何组件的配置文件时,我们将其声明为
@Profile(value="Prod").但我想从属性文件中提供该值.可能吗?如果有,怎么样?
我有一个具有复合键的实体,我试图通过使用 spring data jpa 存储库到 mysql 数据库来持久化它,如下所示:
@Embeddable
public class MobileVerificationKey implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="CUSTOMERID")
private Long customerId;
@Column(name="CUSTOMERTYPE")
private Integer customerType;
@Column(name="MOBILE")
private Long mobile;
@Embeddable
public class MobileVerificationKey implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="CUSTOMERID")
private Long customerId;
@Column(name="CUSTOMERTYPE")
private Integer customerType;
@Column(name="MOBILE")
private Long mobile;
//getter and setters
}
Run Code Online (Sandbox Code Playgroud)
和实体作为
@Entity
@Table(name="mobileverificationdetails")
public class MobileVerificationDetails {
@EmbeddedId
private MobileVerificationKey key;
@Column(name="MOBILETYPE")
private String mobileType;
@Column(name="MOBILEPIN")
private Integer mobilePin; …Run Code Online (Sandbox Code Playgroud) 因为我设置了最大文件上传限制,所以我得到了
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 2097152 bytes
Run Code Online (Sandbox Code Playgroud)
上传文件时出错.我的api给出了500错误,我应该处理这个错误并以JSON格式返回响应而不是错误提供ErrorController
我想捕获该异常并且不给予JSON响应ErrorPage.
@RequestMapping(value="/save",method=RequestMethod.POST)
public ResponseDTO<String> save(@ModelAttribute @Valid FileUploadSingleDTO fileUploadSingleDTO,BindingResult bindingResult)throws MaxUploadSizeExceededException
{
ResponseDTO<String> result=documentDetailsService.saveDocumentSyn(fileUploadSingleDTO, bindingResult);
return result;
}
Run Code Online (Sandbox Code Playgroud)
接受文件的DTO如下
public class FileUploadSingleDTO {
@NotNull
private Integer documentName;
private Integer documentVersion;
@NotNull
private MultipartFile file;
}
Run Code Online (Sandbox Code Playgroud) 我希望能够使用Google Maps API为我提供给定位置的最近地标列表.考虑一种情况,我给Maps API提供纬度和经度,作为回报,它给出了一个地标列表(纬度和经度坐标的集合).这可以使用Maps API吗?
我在VPC中有私有子网,路由表如下:
XX.X.0.X/16 local
0.0.0.0/0 nat-0XXXXXXXXX
Run Code Online (Sandbox Code Playgroud)
使用上述配置,AWS CodeDeploy失败并显示错误,因为Error code: HEALTH_CONSTRAINTS没有日志条目/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log.
但是当我通过添加带有以下路由表的Internet Gateway来更改它以允许公共访问时,AWS CodeDeploy成功地获得了竞争.
XX.X.0.X/16 local
0.0.0.0/0 igw-0XXXXXXXXX
Run Code Online (Sandbox Code Playgroud)
我错过了其他任何配置吗?
我知道spring数据休息会将你的存储库导出为REST服务.但我想知道使用spring数据jpa的优点.
spring ×5
spring-boot ×5
java ×3
spring-data ×2
spring-mvc ×2
amazon-ec2 ×1
amazon-elb ×1
aws-vpc ×1
google-maps ×1
jpa ×1
mysql ×1
redirect ×1
sql-scripts ×1
ssl ×1
tomcat ×1