我在我的REST控制器中使用Spring数据分页并返回Paged实体.我想在JSONViews的帮助下控制作为JSON返回的数据.
当我返回一个对象时,我能够实现结果.但是当我返回Page时,我收到空白的JSON作为回复.
以下是我的方法签名.
@JsonView(TravelRequestView.MyRequests.class)
@RequestMapping("/travel/requests")
public Page<TravelRequest> getUserTravelRequests(
@RequestParam("ps") int pageSize, @RequestParam("p") int page,
@RequestParam(defaultValue = "", value = "q") String searchString)
Run Code Online (Sandbox Code Playgroud)
我删除@JsonView注释时能够收到响应.
以下是我的授权服务器配置:
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
@Configuration
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("acme").secret("acmesecret")
.authorizedGrantTypes("authorization_code", "refresh_token", "password").scopes("openid")
.autoApprove(true);
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");
}
}
Run Code Online (Sandbox Code Playgroud)
和Web安全配置:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@Order(-20) // Very important
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(authenticationManager); …
Run Code Online (Sandbox Code Playgroud) 我们正在应用程序中使用Spring Data JPA,并且正在使用Hibernate Validator验证要保存到数据库中的实体。根据Hibernate Validator文档,有一项功能可提供验证组,以在保存之前验证实体的少量属性。
现在,关于在Spring中使用这些验证器的问题,我唯一能找到的方法就是在控制器中使用@Validated
注解来验证输入,以使用它们。
我们有一个Repository.save()
通过传递实体进行调用的要求,我们需要提供验证组以仅验证少数项目。
spring hibernate hibernate-validator bean-validation spring-data-jpa
我们有一个使用Spring Boot构建的Web应用程序,并且正在使用Spring Security来管理身份验证。身份验证现在正在使用基本模式进行。
我们正在使用UserDetailsService处理身份验证。当我们使用嵌入式tomcat直接从STS运行应用程序时,如果未启用用户,则会收到状态代码为401的以下错误。
{"timestamp":1485512173312,"status":401,"error":"Unauthorized","message":"User is disabled","path":"/trex/user"}
Run Code Online (Sandbox Code Playgroud)
但是,当我将应用程序打包打包并部署到Tomcat时,我们不再收到json错误。而是,我们收到类似于以下内容的html错误。
<html><head><title>Apache Tomcat/7.0.75 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - User is disabled</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>User is disabled</u></p><p><b>description</b> <u>This request requires HTTP authentication.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.75</h3></body></html>
Run Code Online (Sandbox Code Playgroud)
是否可以停止处理标准错误代码,并让json数据按原样传递回去?
编辑: 春季安全配置
/**
* Security configuration. Defines configuration methods and security
* constraints. Autowired bean definitions can be found in …
Run Code Online (Sandbox Code Playgroud) error-handling spring-mvc spring-security tomcat7 spring-boot
如何用变量替换 terraform 脚本的整个块?例如,
resource "azurerm_data_factory_trigger_schedule" "sfa-data-project-agg-pipeline-trigger" {
name = "aggregations_pipeline_trigger"
data_factory_id = var.data_factory_resource_id
pipeline_name = "my-pipeline"
frequency = var.frequency
schedule {
hours = [var.adf_pipeline_schedule_hour]
minutes = [var.adf_pipeline_schedule_minute]
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,如何schedule
使用 terraform 变量使整个块可配置?
我尝试过这个,但它不起作用。
schedule = var.schedule
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Socket.io 部署到 heroku 的 Node JS 应用程序。我已按照https://devcenter.heroku.com/articles/node-websockets提供的步骤正确设置代码,但不知何故,我似乎无法正确使用 Web 套接字。
我的所有套接字轮询请求都失败并出现以下错误。
{"code":1,"message":"会话 ID 未知"}
当我在本地运行相同的代码时,它似乎工作正常。
客户
function createSocket() {
socket = io();
socket.on('connect', function () {
socket.emit('registerUser', { userEmail: $scope.userInfo.userEmail });
});
socket.on('list_of_files', function (data) {
$timeout(function () {
$scope.fileList = data;
});
});
}
Run Code Online (Sandbox Code Playgroud)
服务器
var io = require('socket.io')(server);
io.sockets.on('connection', function (socket) {
socket.on('registerUser', function (data) {
socketClients[data.userEmail] = socket;
});
});
Run Code Online (Sandbox Code Playgroud)
我还启用了heroku的会话亲和力但仍然没有运气
spring ×3
java ×2
spring-mvc ×2
heroku ×1
hibernate ×1
json ×1
node.js ×1
oauth-2.0 ×1
pagination ×1
socket.io ×1
sockets ×1
spring-boot ×1
terraform ×1
tomcat7 ×1