我的授权服务在成功时返回http 204,在失败但是没有responseBody时返回http 401.我无法使用RestTemplate客户端使用它.它无法尝试序列化响应.杰克逊的错误表明我打开了序列化程序中的FAIL_ON_EMPTY_BEANS,但是如何在restTemplate中设置它
客户消耗其余的api
@SuppressWarnings("rawtypes")
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
RestTemplate restTemplate = new RestTemplate();
System.out.println("\n\n\n\n ============API REQUEST INTERCEPTOR=============== \n\n\n\n\n");
if(StringUtils.isBlank(request.getHeader(AuthenticationKeys.AUTHENTICATIONTOKEN.name().toLowerCase()))){
//TODO AUTHORIZE TOKEN
ResponseEntity<AuthenticationResponse> authenticateResponse = restTemplate.getForEntity(authenticateUrl, AuthenticationResponse.class);
if(authenticateResponse.getStatusCode().is2xxSuccessful()){
//TODO SET THE TOKEN IN THE CONTEXT
return true;
}else{
//TODO DO SOME ERROR HANDLING
return false;
}
}else{
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setToken("TESTNG");
ResponseEntity<Object> authorizationResponse = restTemplate.postForEntity(authorizeUrl, request, Object.class);
if(authorizationResponse.getStatusCode().is2xxSuccessful()){
return true;
}else{
//TODO DO SOME ERROR HANDLING
if(authorizationResponse.getStatusCode().equals(HttpStatus.UNAUTHORIZED)){
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Oops! …Run Code Online (Sandbox Code Playgroud) 有没有办法从XML打开Spring的Async配置?我看到的所有示例都使用程序化上下文声明和使用@EnableAsync
是否有XML等价物.在某些地方,我看到<context:annotation-config />被使用,但这没有提到任何关于异步的事情.
我正在使用Spring 4.
是否存在可以提升多个限定bean之一的@Primary的XML等价物
示例场景:
我有一个启动了自动配置的spring-boot应用程序.我已经定义了多个数据源,但是spring无法选择其中一个数据源作为默认值.
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: mysqlDataSource,oracleDataSource
Run Code Online (Sandbox Code Playgroud)
datasources.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<bean id="mysqlDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mcs" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="oracleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:test" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
</beans>
Run Code Online (Sandbox Code Playgroud) 为了将文件从angular上传到Spring MVC REST WebService,人们似乎在AJAX请求中设置了Content-Type:undefined头.
这种内容类型的目的是什么?Spring MultiPart需要它吗?
$http.post(uploadUrl, fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
//...
}
Run Code Online (Sandbox Code Playgroud) 有什么方法可以支持在Hibernate 5.1.1中将java.time.ZoneId持久映射到字符串。现在,它以二进制形式保存ZoneId。
我刚刚升级到具有Hibernate 5.1.1的Grails 3.2.1。例如,保存java.time.Instant效果很好,但是java.time.ZoneId仅以二进制形式存储。
我认为没有Hibernate的支持。那么我该如何编码自己的映射。我尝试使用Jadira Framework,但由于启动grails应用程序时存在一些冲突(例外),因此无法使用。
spring ×4
java ×2
angularjs ×1
asynchronous ×1
file-upload ×1
grails ×1
grails-3.0 ×1
hibernate ×1
jackson ×1
javascript ×1
jpa ×1
rest ×1
resttemplate ×1
spring-mvc ×1
xml ×1