Tag: spring

com.sun.jndi.ldap.LdapCtxFactory:在servlet中找不到类

早上好/下午好, 我有LDAP连接器的问题,当我在我的unit testing中使用它没有问题,但是当它在应用服务器环境中调用时,它似乎有类路径问题,但这个类是用java 1.6.17(版本I)提供的使用)。 我使用spring-ldap来启动我的连接。 public static LdapContextSource getLdapContextSource(final String url, final String base) throws Exception { LdapContextSource ldapContextSource = new LdapContextSource(); ldapContextSource.setUrl(url); ldapContextSource.setBase(base); ldapContextSource.setPooled(true); //ldapContextSource.setContextFactory(LdapCtxFactory.class); ldapContextSource.afterPropertiesSet(); return ldapContextSource; } 这是日志: 2010-08-10 09:46:38,183 : StandardWrapperValve.invoke : Servlet.service() for servlet default threw exception java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at org.ow2.easybeans.loader.EasyBeansClassLoader.findClass(EasyBeansClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:303) […]

Spring MVC何时会自动生成HttpSession?

使用AutoWired HttpSession的问题: LoginController调用LoginService传递HttpServletRequest作为参数。 我已经在其他几个带注释的类中自动assembly了HttpSession(但不是在LoginService中): @Autowired private HttpSession httpSession; 在LoginService类中,如果我尝试通过调用request.getSession(false)来获取会话,则在某些情况下我会收到null。 如果我尝试通过调用request.getSession(true)来获取会话,我最终会得到两个HttpSession对象(一个在这里,另一个通过AutoWiring)。 如果我在LoginServic类中自动assemblyHttpSession并从那里使用会话,那么我也将以两个HttpSession对象结束。 何时会创建完全自动assembly的HttpSession? 处理这种情况的最佳方法是什么? 谢谢!

如何增加AsyncRestTemplate类的超时?

我用spring框架和REST开发了一些异步Web服务,我从使用spring类AsyncRestTemplate创建的客户端中使用它。 类返回一个对象ListenableFuture<ResponseEntity> (使用方法getForEntity ),它带来Web服务返回的值(使用方法.get(): )。 它工作正常,但是当Web服务花费很多时间时,方法isDone()的ListenableFuture类返回值true ,即使Web服务尚未完成工作。 如果我尝试使用客户端中的get()方法恢复Web服务响应并且它已经很晚了,我总是得到以下消息: “timestamp”: “2018-05-29T22:42:26.978+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “java.util.concurrent.ExecutionException: org.springframework.web.client.HttpServerErrorException: 503 null”, “path”: “/client/result” 有人知道我该如何解决这个问题? 我希望客户端向我显示Web服务响应,即使Web服务需要花费很多时间(我想增加超时)。 服务器代码如下: 配置类: @Configuration @EnableAsync public class ConfigurationClass { @Bean public Executor threadPoolTaskExecutor() { return new ThreadPoolTaskExecutor(); } } 控制器类: @RestController @RequestMapping(“/server”) public class ControllerClass { @GetMapping(“/start”) @Async public CompletableFuture callService() […]

将自定义AuthenticationProcessingFilter与一起使用(auto-config =“true”)

Spring security(2.0.x)http命名空间,表单登录定义自动使用AuthenticationProcessingFilter。 我也知道如果我设置auto-config=”false”我可以通过提供自定义bean定义来自定义身份validation。 我有CustomAuthenticationProcessingFilter扩展AuthenticationProcessingFilter覆盖acquireUsername并使用自定义逻辑来获取用户名而不是传递的用户名。 protected String obtainUsername(HttpServletRequest request) { // custom logic to return username from parameter/cookies/header etc … } 是否可以使用CustomAuthenticationProcessingFilter,同时仍然使用auto-config=”true” 而无需定义customAuthFilter和所有依赖bean? … …

配置@PathVariable类型不匹配的错误页面

假设我有一个控制器: @Controller public class SomeController { @RequestMapping(value = “{id}/object.do”) public String showObject(@PathVariable(“id”) Integer id, HttpServletRequest request) { //do smth return “somePage”; } } 当“id”不是数字,但字符串如“aaa / object.do”时,Tomcat会向我显示错误 – “客户端发送的请求在语法上是不正确的”。 有没有办法配置一个错误页面,只有当“id”路径变量的类型不正确时才会显示?

Spring框架:HTTP OPTIONS返回所有METHODS(get,put,post,delete,trace,head,options)

我写了一个spring web应用程序。 除了一件事,它非常可靠。 应用程序返回HTTP OPTIONS请求,其响应为“允许:GET,HEAD,POST,PUT,DELETE,OPTIONS”,但这不是真的,只允许GET和POST。 其他操作(GET和POST除外)返回“操作不受支持”错误405和服务器名称和版本…等。 安全团队不喜欢使用“不支持”错误消息返回服务器的所有详细信息。 我花了很多时间试图覆盖该错误页面或为405引入自定义错误页面……但我没有成功。 我整天都在尝试禁用HTTP OPTIONS。 没有成功。 还有一个细节,我运行curl语句来测试: curl “http://localhost:8080/webappX/welcome.htm” -X PUT -v 我的应用程序返回: HTTP Status 405 – Request method ‘PUT’ not supported Tomcat/6.0…etc 由于此数据(tomcat版本,服务器信息和响应元数据)可能用于安全攻击,如何创建隐藏我的服务器详细信息并提供非常小的错误页面的自定义405页面? 或者我如何禁用PUT,DELETE,TRACE,OPTIONS,HEAD以便tomcat可能只是忽略它们或者不提供有关我的服务器的内部信息。 谢谢

Spring @Secured和@PreAuthorize对普通(非Web)应用程序没有任何影响

我用两个安全的方法创建了一个Application Spring组件: @Component public class Application { public void run() { onlyAdminMethod(); onlyAdminMethod2(); } @Secured( “ROLE_ADMIN” ) public void onlyAdminMethod() { System.out.println( “Admin-only method called” ); } @PreAuthorize( “hasRole(‘ROLE_ADMIN’)” ) public void onlyAdminMethod2() { System.out.println( “Admin-only method 2 called” ); } } 我在该bean上调用run()方法,我从Spring XML上下文中获取: ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“applicationContext.xml”); context.getBean( Application.class).run(); 没有发生 –即使没有身份validation和SecurityContextHolder.getContext().getAuthentication() 方法也会正常调用 SecurityContextHolder.getContext().getAuthentication()返回null […]

来自外部jar问题的Spring UTF-8消息资源

我在Spring MVC应用程序中遇到UTF-8消息源的问题。 我已经尝试了AbstractMessageSource的两个实现:ResourceBundleMessageSource和ReloadableResourceBundleMessageSource。 我有一个带有i18n消息的外部jar,包含在com.mypackage.i18n包中 ResourceBundleMessageSource的配置: 此配置加载查找和加载属性,但因UTF-8而失败,因为此实现不支持UTF-8。 ReloadableResourceBundleMessageSource的配置: 此配置找不到属性。 我知道这个具有可重新加载资源的实现需要将属性放在WEB-INF目录中的某个位置,并且如果您不需要重新加载资源,它不会将资源限制在其他位置。 根据类java: 请注意,设置为“basenames”属性的基本名称的处理方式与ResourceBundleMessageSource的“basenames”属性略有不同。 它遵循不指定文件扩展名或语言代码的基本ResourceBundle规则,但可以引用任何Spring资源位置(而不是仅限于类路径资源)。 使用“classpath:”前缀,仍然可以从类路径加载资源,但在这种情况下,除“-1”(永久缓存)之外的“cacheSeconds”值将不起作用。 有人可以建议我如何解决问题:我需要使用另一种方法或以某种方式修改ReloadableResourceBundleMessageSource的配置来从jar中查找资源?

SpringDataRest并显示welcome-file-list / disable链接发现

我在spring-mvc应用程序中使用spring-data-rest(1.0.0.RELEASE)但是我遇到了以下问题 在我的WebConfig中 @Import(RepositoryRestMvcConfiguration.class) public static class WebConfiguration extends WebMvcConfigurationSupport{…} 在这种情况下, RepositoryRestMvcConfiguration有一个bean RepositoryRestController ,它有方法listRepositories(…)注释 @RequestMapping(value = “/”, method = RequestMethod.GET) 现在的问题是,当我在根上下文(“/”)点击时,我得到了我的存储库的链接,如下所示 { “links” : [ { “rel” : “content”, “href” : “http://localhost:7070/appName/content” }, { “rel” : “language”, “href” : “http://localhost:7070/appName/language” } ], “content” : [ ] } 但我想显示index.html文件。 我想在根上下文中禁用链接的发现。 事件我尝试使用我的自定义控制器映射到根上下文(“/”)但是第一优先级的spring与RepositoryRestController’s.listRepositories(…)方法匹配。 它不会出现在我的控制器方法中。 在日志中,它就像这样 **RepositoryRestHandlerMapping**: 185 – Mapped […]

值未填充到gemfire缓存中

我有2个xml配置文件,如下所示 APP-context.xml中: 测试cache.xml info 我有一个名为TestCache.java的测试类 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { “classpath:app-context.xml” }) public class TestCache { @Autowired GemfireTemplate testCache; @Test public void testgetSomeValues() { HashMap map1 = retrieveSomeValues(); HashMap map2 = retrieveSomeValues(); assertEquals(Map1, Map2); } @Cacheable(value = “testCache”) public HashMap retrieveSomeValues() { HashMap obj = new HashMap(); obj.put(“600”, “Auto”); obj.put(“601”, “Life”); return obj; } } 但我发现实际上没有任何东西被缓存到该地区。 […]