Tag: spring

如何使用springframework BeanUtils copyProperties忽略空值?

我想知道如何使用Spring Framework将属性从Object Source复制到Object Dest忽略null值。 我实际上使用Apache beanutils,使用此代码 beanUtils.setExcludeNulls(true); beanUtils.copyProperties(dest, source); 去做吧。 但现在我需要使用Spring。 有帮助吗? 多谢

Spring Security在运行时注销用户

我正在实现一个基于Spring的Web应用程序,它使用Spring Security和DaoAuthenticationProvider。 因此我创建了一个具有布尔值isEnabled()的用户类; 方法因为它实现了Springs UserDetails接口。 因此,如果用户“未启用”,则此用户将无法再登录。 到现在为止还挺好。 如果我在运行时仍然登录时禁用用户,(似乎)此用户保持登录状态,直到http会话结束,但我希望用户在设置禁用后立即登出。 我怎样才能做到这一点? 谢谢。

Spring Generic Dao类名

我已经为我的spring / hibernate项目配置了一个自定义通用服务DAO – 这个想法是我可以从我的控制器中轻松地重用它。 它基本上是这样的: public class DefaultService { private Class e; public String className(Class e) { String clip = e.getName(); clip = clip.substring(clip.lastIndexOf(‘.’) + 1, clip.length()); return clip; } public List getAll(Integer status) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery(“FROM ” + className(e) + ” WHERE status = ” + status); […]

带有项目/实体集合的Spring Cache

我正在使用Spring Cache,我在其中传递了一组键,返回是一个实体列表。 我想让缓存框架理解返回列表中的每个元素都要使用相应的代码进行缓存。 目前,似乎关键是整个列表,如果我在后续调用中缺少一个键,它将尝试再次重新加载整个集合。 @Override @Cacheable(value = “countries”) public List getAll(Listcodes) { return countryDao.findAllInCodes(codes); } 另一种可能性是返回是一个映射,同样我希望缓存足够智能,只能查询以前从未查询过的项目,也用它的密钥缓存每个项目。 @Override @Cacheable(value = “countries”) public Map getAllByCode(Listcodes) { return countryDao.findAllInCodes(codes); } 假设国家类看起来像这样: class Country{ String code; String fullName; long id; … // getters setters constructurs etc.. } 这可以用Spring Cache吗?

Spring究竟是如何引导的?

有谁知道Spring实际上是如何引导的? 创建了哪些实例以及由谁创建? 我真的想知道是谁创建了WebApplicationContext和ContextLoader的实例。 这是Tomcat的工作吗?

在DispatcherServlet中找不到带有URI 的HTTP请求的映射,名称为“java4s”

早些时候我的代码工作但现在我遇到这个错误有时代码工作,有时它不起作用。 我的代码是 Java4sController.java package java4s; import javax.validation.Valid; import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServlet; //import javax.servlet.*; import javax.servlet.http.*; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import java.sql.*; //import org.h2.jdbcx.JdbcConnectionPool; //import org.springframework.security.core.context.SecurityContextHolder; @Controller public class Java4sController { HttpSession session; String uname=””,pass=””; Statement stmt; Connection conn; @RequestMapping(value=”displayForm.html”, method=RequestMethod.GET) public String helloWorld(UserDetails ud,HttpServletRequest request,HttpServletResponse response) { return “loginPage”; […]

Spring Boot + Oauth2客户端凭据

我正在尝试使用带有客户端凭据流的Oath2来保护我在Spring Boot上的微服务。 顺便说一句,那些微服务只会通过中间件层互相交谈,我的意思是不需要用户凭证来允许授权(用户登录过程如Facebook)。 我在Internet上查找了示例,了解如何创建授权和资源服务器来管理此通信。 但是我刚刚找到了解释如何使用用户凭据(三条腿)来解释它的示例。 有没有人有任何示例如何在Spring Boot和Oauth2中做到这一点? 如果可以提供有关所使用范围的更多详细信息,则令牌交换将不胜感激。

无法在不同的Spring启动应用程序中的不同端口上启动2个嵌入式active-mq

我有2个弹簧启动应用程序。 每个应用程序都嵌入了活动的mq代理。 我需要并行处理同一台PC上的2个应用程序,但它现在不起作用。 第一个应用程序始终成功启 2018-02-02 11:48:20.095 INFO 7660 — [ main] scaAnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@53045c6c: startup date [Fri Feb 02 11:48:20 MSK 2018]; root of context hierarchy 2018-02-02 11:48:20.923 INFO 7660 — [ JMX connector] oaabroker.jmx.ManagementContext : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:7777/jmxrmi 2018-02-02 11:48:20.923 INFO 7660 — [ main] o.apache.activemq.broker.BrokerService : Using Persistence Adapter: […]

如何在Spring MVC中实现HTTP字节范围请求

我的网站上有video倒带的问题。 我找出了http标题的问题。 我当前的控制器方法返回video: @RequestMapping(method = RequestMethod.GET, value = “/testVideo”) @ResponseBody public FileSystemResource testVideo(Principal principal) throws IOException { return new FileSystemResource(new File(“D:\\oceans.mp4”)); } 如何用字节范围支持重写以下代码? PS 我见过以下示例http://balusc.blogspot.in/2009/02/fileservlet-supporting-resume-and.html 但是这段代码看起来很难,我无法理解。 我希望在springmvc存在方式更简单。

如何在Spring Boot中以编程方式创建bean?

我有一个应用程序,其中包含application.properties中列出的许多数据源设置。 我有一个@ConfigurationProperties类来加载这些设置。 现在我想从这个ConfigurationProperties类中获取值,并使用它们即时创建DataSource bean。 我尝试过使用@PostConstruct并实现BeanFactoryPostProcessor 。 但是,使用BeanFactoryPostProcessor ,处理似乎很早就发生了 – 在我的ConfigurationProperties类已经填充之前。 如何使用Spring Boot快速读取属性并创建DataSource bean? 这是我的application.properties的样子: ds.clients[0]=client1|jdbc:db2://server/client1 ds.clients[1]=client2,client3|jdbc:db2://server/client2 ds.clients[2]=client4|jdbc:db2://server/client4 ds.clients[3]=client5|jdbc:db2://server/client5 我的ConfigurationProperties类: @Component @ConfigurationProperties(prefix = “ds”) public class DataSourceSettings { public static Map CLIENT_DATASOURCES = new LinkedHashMap(); private List clients = new ArrayList(); public List getClients() { return clients; } public void setClients(List clients) { this.clients = clients; […]