小编Mas*_*ode的帖子

用于AWS ELB和Tomcat7服务器的HTTP到HTTPS重定向

我有一个指向AWS ELB的子域(test.XXXX.com),它接受HTTP(80)和HTTPS(443)请求.我已为443的HTTPS连接配置了SSL认证.我已经尝试通过更改web.xml和server.xml来在Tomcat级别进行HTTP到HTTPS重定向,如中所述

http://www.journaldev.com/160/steps-to-configure-ssl-on-tomcat-and-setup-auto-redirect-from-http-to-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.

在此输入图像描述

ssl redirect tomcat amazon-ec2 amazon-elb

10
推荐指数
1
解决办法
2169
查看次数

春季启动时@InitBinder无法使用@RequestBody

如果我使用@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

spring spring-mvc spring-boot

8
推荐指数
2
解决办法
8944
查看次数

在Spring boot中:找不到模板位置:类路径资源[模板/](请添加一些模板或检查您的Thymeleaf配置)

我已经浏览了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-mvc-test spring-boot

6
推荐指数
1
解决办法
1万
查看次数

Spring Boot数据库初始化MySQLException for Trigger

我正在使用 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)

java mysql sql-scripts spring-boot

6
推荐指数
1
解决办法
3579
查看次数

将@Profile注释与属性占位符值一起使用

当我们在spring中定义任何组件的配置文件时,我们将其声明为 @Profile(value="Prod").但我想从属性文件中提供该值.可能吗?如果有,怎么样?

spring spring-boot

5
推荐指数
2
解决办法
1181
查看次数

spring data jpa复合键重复键记录插入导致更新

我有一个具有复合键的实体,我试图通过使用 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)

java spring jpa spring-data spring-data-jpa

5
推荐指数
1
解决办法
1万
查看次数

多部分文件上载:弹出引导返回JSON错误消息中的大小超过异常

因为我设置了最大文件上传限制,所以我得到了

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)

spring multipartform-data spring-mvc spring-boot

5
推荐指数
1
解决办法
8599
查看次数

如何使用Google Maps API查找指定位置附近的地标?

我希望能够使用Google Maps API为我提供给定位置的最近地标列表.考虑一种情况,我给Maps API提供纬度和经度,作为回报,它给出了一个地标列表(纬度和经度坐标的集合).这可以使用Maps API吗?

google-maps google-maps-api-3

4
推荐指数
1
解决办法
6965
查看次数

AWS CodeDeploy无法在私有VPC中工作

我在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)

我错过了其他任何配置吗?

amazon-web-services aws-code-deploy aws-vpc

3
推荐指数
1
解决办法
1371
查看次数

使用Spring Data REST而不是Spring Data JPA有什么好处?

我知道spring数据休息会将你的存储库导出为REST服务.但我想知道使用spring数据jpa的优点.

java spring spring-data spring-data-jpa spring-data-rest

1
推荐指数
2
解决办法
2789
查看次数