Tag: spring

Spring Deferred结果丢失了http会话

我在异步模式下使用带有Spring MVC和Spring安全性的Tomcat 7。 然后我使用DeferredResult来发出异步请求。 该机制工作正常,但问题是当deferredResult使setResult()并返回promise时,我丢失了所有会话,并且我的下一个请求给了我403禁止,因为我没有在SecurityContextHolder上进行身份validation。 我想是因为promise的返回是在另一个没有会话的线程中完成的。 有人可以把我放在正确的方向。 解决方案:onCompletion回调方法我传递了在地图中创建deferredResult时放置的会话。 deferredResult.onCompletion(new Runnable() { @Override public void run() { request.getSession().setAttribute(SPRING_SECURITY_CONTEXT, securityContextContainer.get(deferredResult)); securityContextContainer.remove(deferredResult); } });

Java Spring:POST Request在传递JSON对象时输出意外的415错误

我正在创建一个接收以下输入的API,并提供以下输出。 所以我需要有一个猜测function。 到目前为止,我还没有运气测试我的代码。 当我发送POST(使用POSTMan)到http:// localhost:8080 / guess时身体为{“game”:”klubxb”, “guess”:”a”} 。 我将Content-type设置为application/json ,并且正文为{“game”:”lmzxmn”,”guess”:”c”} 这是回应: { “timestamp”: “2018-04-28T00:40:29.141+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “No message available”, “path”: “/guess” } 我为猜测定义的函数是: @RequestMapping(value = “/guess”, method = RequestMethod.POST, consumes = “application/json”, produces = “application/json”) public Game makeGuess(@RequestBody Guess gameAndLetter, HttpSession session) throws GameDoesNotExistException, InvalidCharacterException{ String game = gameAndLetter.getGame(); […]

不能在spring boot quartz中使用autowired feign client

我正在使用Netflix-OSS的 Spring启动它是一个很好的微服务系统,工作正常,我正在使用Feign Client ,以便在服务和Quartz之间建立连接以运行后台作业。 但是当我在工作中使用Autowired feign-client时会出现问题。 @FeignClient(value = “user”, configuration = {OAuthFeignConfig.class}, fallback = UserClientFallback.class) public interface UserClient { @RequestMapping(value = “/api/user/get/userName/{userName}”, method = RequestMethod.GET) UserInfoResponse getUserInfoByUserName(@PathVariable(“userName”) String userName); 和石英代码: public class DoJob extends RunnableTask { @Autowired private UserClient userClient; @Override public int run(JobExecutionContext jobExecutionContext) { userInfoById = userClient.getUserInfoById(“123e4567-e89b-12d3-a456-426655440000”); return userinfo.getIntId(); } } 和例外是: Error […]

如何在Web应用程序中使用Netty – 采取适当的配置步骤

我正在尝试将Netty设置为在我的Web应用程序中运行嵌入式。 我找到了以下文档: http : //docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/socket/http/package-summary.html#package_description ,它描述了如何配置Web。启动Netty servlet的xml文件。 现在该文件说: 其次,您必须使用本地传输将基于Netty的服务器应用程序绑定在相同的Servlet上下文或共享类加载器空间中(请参阅LocalServerChannelFactory。)您可以使用您喜欢的IoC框架(如JBoss Microcontainer,Guice和Spring)来执行此操作。 以下示例显示如何将echo服务器绑定到JBossAS 5中上面指定的端点(web.xml): 这听起来很合理,但我不清楚 – 实际上 – 应该如何运作。 假设我想使用Spring作为Ioc容器,将netty绑定到本地传输的正确bean配置是什么? 另外,我如何启动Spring上下文? 来自web.xml? 谢谢

Spring MVC @RequestParams

这是url: https : //192.168.33.10/openmrs/ws/rest/v1/bahmnicore/bahmniencounter/search? includeAll = false & patientUuid = 210d0739-7937-4fb7-8f53-752f393cb4b7 & visitUuid = c1c26908-3f10-11e4-adec- 0800271c1b75 它登陆Spring MVC的控制器方法 – @RequestMapping(method = RequestMethod.GET, value = “search”) @ResponseBody public List search(@RequestParam(“patientUuid”) String patientUuid, @RequestParam(value = “fromDate”, required = false) String date, String visitUuid) throws Exception { if (visitUuid != null) { return bahmniDiagnosisService.getBahmniDiagnosisByPatientAndVisit(patientUuid, visitUuid); } else { […]

Spring Retry Junit:使用自定义重试策略测试重试模板

我正在尝试测试使用自定义重试策略的重试模板。 为了做到这一点,我使用这个例子: https://github.com/spring-projects/spring-retry/blob/master/src/test/java/org/springframework/retry/support/RetryTemplateTests.java#L57 基本上,我的目标是在我获得某些特定的http错误状态(例如http 500错误状态)时测试我的重试逻辑。 这是我的junit的xml上下文: CustomRetryPolicy就像: public class CustomRetryPolicy extends ExceptionClassifierRetryPolicy { private String maxAttempts; @PostConstruct public void init() { this.setExceptionClassifier(new Classifier() { @Override public RetryPolicy classify(Throwable classifiable) { Throwable exceptionCause = classifiable.getCause(); if (exceptionCause instanceof HttpStatusCodeException) { int statusCode = ((HttpStatusCodeException) classifiable.getCause()).getStatusCode().value(); return handleHttpErrorCode(statusCode); } return neverRetry(); } }); } public void setMaxAttempts(String […]

java.lang.NoSuchMethodError:org.springframework.util.ReflectionUtils.clearCache()

我遇到了一个问题,谷歌是这一天的一半。 什么都没有帮助我。 它工作正常。 但在那之后发生了一些事情,我没有抓住这一点。 这是TomCat Catalina Log 31-Jan-2016 00:35:27.278 INFO [RMI TCP Connection(2)-127.0.0.1] null.null HHH000412: Hibernate Core {5.0.7.Final} 31-Jan-2016 00:35:27.282 INFO [RMI TCP Connection(2)-127.0.0.1] null.null HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=update} 31-Jan-2016 00:35:27.283 INFO [RMI TCP Connection(2)-127.0.0.1] null.null HHH000021: Bytecode provider name : javassist 31-Jan-2016 00:35:27.376 INFO [RMI TCP Connection(2)-127.0.0.1] null.null […]

SpringXD和Spring Integration:每隔X分钟从kafka主题中读取一遍,然后发送到另一个主题

我正在尝试实现一个解决方案来创建一个由kafka源,桥接模块和kafka接收器组成的SpringXD流。 所以我有类似的东西: 我的问题是我想以某种方式避免使用轮询器。 基本上是因为当这些消息在队列中时我想避免将消息保留在内存中。 我宁愿每隔X分钟从kafka读取一次,只需从队列中取出Y消息,然后将这些消息发送到下一个主题。 看起来我无法摆脱队列,但后来我的问题是:还有其他选择吗? 我不喜欢把东西留在内存中,但我也不想使用这个选项: http : //docs.spring.io/spring-integration/reference/html/system-management-chapter.html#message -商店

解析Mapper XML时出错。 原因:java.lang.NullPointerException

我一直在尝试从mybatis2转换为mybatis3,它给我带来了各种各样的问题。 从sqlMapConfig.xml我得到一个Error Parsing Mapper XML sqlMapConfig.xml ,我采取它意味着有一些错误,但我无法看到它。 我非常感谢任何帮助。 sqlMapConfig.xml beans.xml中 classpath:jdbc.properties search_sql.xml SELECT person_full_name, assignment_number, corp_id, supervisor_name, scoping_6 FROM $table_name$ WHERE plan_id = $plan_id$ LOWER(last_name) like ‘$emp_lname$%’ LOWER(first_name) like ‘$emp_fname$%’ LOWER(assignment_number) like ‘$payId$%’ LOWER(corp_id) like ‘$corp_id$%’ LOWER(supervisor_name) like ‘$manager_lname$%’ LOWER(supervisor_name) like ‘%, $manager_fname$%’ 堆栈跟踪 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlMapClient’ defined in class path […]

如何将Spring URL映射到/ WEB-INF / views中的JSP文件?

我在使用Spring(使用3.0.5.RELEASE)映射时遇到了麻烦。 我想将URL http://mydomain/context-path/user/registrationform.jsp映射到我的JSP页面 /WEB-INF/views/user/registrationform.jsp 但我得到了404.我的控制器设置如此…… @Controller @RequestMapping(“registrationform.jsp”) public class RegistrationController { private static Logger LOG = Logger.getLogger(RegistrationController.class); … public void setRegistrationValidation( RegistrationValidation registrationValidation) { this.registrationValidation = registrationValidation; } // Display the form on the get request @RequestMapping(method = RequestMethod.GET) public String showRegistration(Map model) { final Registration registration = new Registration(); model.put(“registration”, registration); return “user/registrationform”; } […]