草庐IT

java - Redis token 存储

我想在集群环境中部署我的RESTAPI。为此,我需要将我的OAuth2.0token存储在共享token存储中。目前我正在使用SpringSecurity的InMemoryTokenStore,它不能在多节点集群上共享。我打算使用Redis存储token。我发现最新版本的Spring-SecurityOAuth即2.8.0也提供了RedisTokenStore。我对此有一些疑问:在现有的spring-securityxml配置中使用RedisTokenStore需要进行哪些更改。目前我正在使用InMemoryTokenStore。如何使RedisTokenStore可与集群中的所有节点

java - 使用 Spring 引导在 Intellij 中实时加载 Assets

在不使用Springboot技术的情况下使用Spring时,我可以使用TomcatMaven插件启动应用程序并更新我的html、css和js,而无需重新启动服务器以使更改在浏览器中生效。现在,当使用Springboot执行此操作时,每次我更改静态Assets中的某些内容时,我都必须在IntelliJ中执行Make任务,否则我将不会在浏览器中看到更改。我的SpringBoot应用程序也使用了devtools依赖项,我在查看时将浏览器连接到实时重新加载套接字。此配置仍然没有显示我在静态文件中所做的更改。我需要做什么才能让它正常工作? 最佳答案

java - Spring REST - 验证原始 GET 请求参数

有没有一种方法可以使用注释来验证原始(int、String等)GET参数?@RequestMapping(value="/api/{someInt}",method=RequestMethod.GET,produces=MediaType.TEXT_PLAIN_VALUE)publicResponseEntitysomeRestApiMethod(@PathVariable@Valid@Min(0)@Digits(integer=10,fraction=0)intsomeInt){//...returnnewResponseEntity("sample:"+someInt,HttpSt

java - Spring 和 Hibernate 的事务管理使非 Activity 事务成为可能

我正在使用Spring和Hibernate管理一个JavaWeb应用程序。我使用Spring和Hibernate工具来处理持久性级别,因此我不需要提交\回滚我的事务。该应用程序是并发的,因此用户可以修改相同的记录,我决定使用ReadCommitted作为隔离级别。问题是有时我会在日志中发现JDBC错误,并且所有下一个请求都会出现相同的错误,从而阻止应用程序行为。这些是事务管理中涉及的组件:@BeanpublicSpringLocalSessionFactoryBeansessionFactory(DataSourcedataSource){SpringLocalSessionFacto

java - Spring,使用 POST 重定向到外部 url

在接下来的Spring3.1操作中,我必须做一些事情并将属性添加到POST请求,然后通过POST将其重定向到外部URL(我不能使用GET)。@RequestMapping(value="/selectCUAA",method=RequestMethod.POST)publicModelAndViewselectCUAA(@RequestParam(value="userID",required=true)Stringcuaa,ModelMapmodel){//query&other...model.addAttribute(PARAM_NAME_USER,cuaa);model.add

java - Spring @Value 注释返回 null

我正在尝试利用@Value注释并从属性文件自动填充我的字符串变量,但没有成功。值未设置且为null。这是我的配置:SendMessageController.java@RestControllerpublicclassSendMessageController{@Value("${client.keystore.type}")privatestaticStringkeystoreType;@RequestMapping(value="/sendMessage",method=RequestMethod.POST)publicResponseEntitysendMessage(@Vali

java - 为什么我的自定义 PermissionEvaluator 没有被调用?

我正在为我的SpringSecurity配置而苦苦挣扎,到目前为止我无法让它工作。我不知道为什么我的自定义PermissionEvaluator没有被调用并且我使用hasPermission表达式的@PreAuthorize注释被忽略。我正在使用Spring4.2.4和Springsecurity4.1.0她是我的代码:网络安全配置@Configuration@EnableWebSecuritypublicclassMyWebSecurityConfigextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure

java - 仅验证选定的其余端点 : spring boot

我有一个SpringBootWeb应用程序,它公开了几个rest端点。我想知道我们如何才能只为选定的其余端点启用基本身份验证。假设我只想对/employee/{id}请求进行身份验证,而忽略所有其他其余端点。我正在使用以下代码。我的问题是antMatcher是否只验证指定的请求?目前它为所有其余端点启用身份验证:@Configuration@EnableWebSecuritypublicclassWebSecurityConfigextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure(HttpSecurit

java - 在 Spring Boot 1.4 中测试安全性

我正在尝试使用SecurityConfig类中定义的自定义安全设置来测试@WebMvcTest:@Configuration@EnableWebSecuritypublicclassSecurityConfigextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException{http.authorizeRequests().antMatchers("/admin*").access("hasRole('ADMIN')").antMatchers("/*

java - Hibernate : could not initialize proxy - no Session 中的 LazyInitializationException

我从我的服务中调用dao@Override@TransactionalpublicProductgetProductById(intid){returnproductDao.getProductById(id);}在dao中我得到的产品是@OverridepublicProductgetProductById(intid){Productp=sessionFactory.getCurrentSession().load(Product.class,id);System.out.print(p);returnp;}这运行良好,但如果我将我的dao类更改为@OverridepublicPr