Tag: spring

Spring数据restvalidation+exception映射器:令人困惑

我正在使用Spring Data Rest,一切顺利。 我想在我的实体上应用validation(JSR 303)。 春季文档说我可以通过几种方式拦截应用程序事件(我无法开始工作,而现在spring.io似乎已经失效)。 但是,我确实通过推杆让它发挥作用 @Validated 在我的存储库: @Validated @RepositoryRestResource(collectionResourceRel = “workers”, path = “workers”) public interface WorkerRepository extends PagingAndSortingRepository { } 它会引发exception。 问题是它是一个弹簧exception而不是根目录,我需要基本上进行validation并将它们转换为自定义实体有效负载: { “foo”: “must be of length 10”, “baz”: “Must match pattern ‘[AZ]+'” } 所以,简而言之,我想 使用JSR 303validation实体 生成具有400的HTTP实体:以及映射或字段 – >错误 最简单的方法是什么? 我也偶然发现了这个: Detected @ExceptionHandler methods in repositoryRestExceptionHandler 这看起来很可疑。 当我结账时,它看起来像我需要的肯定

ClassNotFoundException:org.hibernate.hql.internal.ast.HqlToken甚至在添加了classic.ClassicQueryTranslatorFactory 之后

可能重复: org.hibernate.HibernateException:无法实例化QueryTranslatorFactory:org.hibernate.hql.classic.ClassicQueryTransactionFactory 我正在使用Hibernate 4,Spring 3和JSF 2.0。 我正在运行jsf页面 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.internal.ast.HqlToken [select generatedAlias0 from net.test.model.Request as generatedAlias0] 我已经在applicationContext.xml中的hibernate属性下面有以下内容 org.hibernate.hql.internal.classic. ClassicQueryTranslatorFactory 请注意我已经添加了org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean和org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter ,我怀疑在添加之后我再次获得org.hibernate.QueryException: ClassNotFoundException 我的问题是什么是ClassicQueryTranslatorFactory属性的ClassicQueryTranslatorFactory ? 如果没有这样的属性我怎么能解决这个问题? applicationContext.xml中 net.test.model.Request org.hibernate.dialect.Oracle10gDialect true org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory <!– Enable the configuration of transactional behavior based on annotations –> <!– Transaction Manager is defined –>

禁止使用Hibernate Envers为实体创建_AUD表?

如何禁用实体的Hibernate Envers创建_AUD表? 我想通过使用AuditListeners而不是允许控制Hibernate来创建表来进行自定义审计。

Hibernate自定义架构创建

create创建一个新的数据库模式, update create如果它不存在并更新现有数据库架构。 如果我想检查数据库模式是否存在,并且根据将创建数据库模式,我该如何实现。 目前我的applicationContext.xml的配置是: info.ems.models.User info.ems.models.Role org.hibernate.dialect.HSQLDialect true create 和HibernateEMSDao.java: public class HibernateEMSDao implements EMSDao { private final Logger logger = LoggerFactory.getLogger(getClass()); private HibernateTemplate hibernateTemplate; public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } public void saveUser(User user) { hibernateTemplate.saveOrUpdate(user); } public List listUser() { return hibernateTemplate.find(“from User”); } public void createSchema() { […]

使用ResponseBody下载spring文件

您好我正在尝试创建一个允许我托管任何类型文件的应用程序。 为了做到这一点,我正在执行以下魔术: @RequestMapping(value = “/files/{file_name}”, method = RequestMethod.GET) @ResponseBody public FileSystemResource getFile( @PathVariable(“file_name”) String fileName) { System.out.println(fileName); String filePath = “./files/”; return new FileSystemResource(new File(filePath+fileName)); } 但这种方法带来了三个不必要的问题 一些随机数据被附加到文件中 该文件在浏览器窗口中打开而不是下载 – 我试图使用类似的东西来破解它 produce =“application / octet-stream” 但它只导致406错误。 test.txt被截断到测试中,我找到了一个解决方案,为应用程序提供test.txt /作为fileName,但它看起来有点乱。

如何有效地使用HttpComponentsClientHttpRequestFactory和RestTemplate?

我在我的一个项目中使用RestTemplate及其工厂HttpComponentsClientHttpRequestFactory 。 在这个项目中,我需要对我的服务器进行Http url调用,该服务器运行一个restful服务,它将响应作为JSON字符串返回。 以下是我的代码 – public class GetUserClientData { public String getData(KeyHolder keys) { return new HTTPRequestAccess(keys).makeHttpRequest(); } } 下面是我的包装HttpClient部分的类 – public class HTTPRequestAccess { // should this be static? private RestTemplate restTemplate; private KeyHolder keys; private int timeout; public HTTPRequestAccess(KeyHolder keys){ this(keys.getTimeoutValue()); // setting timeout to RestTemplate this.keys = keys; } public HTTPRequestAccess(int […]

具有角色的经过身份validation的用户的Spring Security Java配置

我试图使用Spring Boot使用Java配置来配置Spring Security。 我的WebSecurityConfig类有一个这样的配置方法 @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers(“/”, “/login”, “/css/**”, “/js/**”, “/img/**”, “/bootstrap/**” ).permitAll() .antMatchers(“/individual”, “/application”, “/upload”).hasRole(“USER”) .and() .formLogin() .loginPage(“/login”) .successHandler(successHandler); } 我为未经身份validation的用户提供了登录页面,并且用户进行了身份validation。 但是,当尝试访问url /个人时,我得到403错误,这在日志中 2015-11-12 13:59:46.373 DEBUG 34468 — [nio-8090-exec-6] osswumatcher.AntPathRequestMatcher : Checking match of request : ‘/individual’; against ‘/’ 2015-11-12 13:59:46.373 DEBUG 34468 — [nio-8090-exec-6] osswumatcher.AntPathRequestMatcher […]

Crudrepository /从其他表到实体的单个字段作为只读

因为我犯的任何错误,请耐心等待,因为这是我的第一个问题。 我有一个包含两个表的数据库,一个名为PERSON的表 使用以下实体: @Entity class Person { @Id private String guid; private String firstName; private String organisationGuid; … … } 一个表叫做: 组织 使用以下实体: @Entity class Organisation { @Id private String guid; private String name; … … } 如您所见,每个人都属于一个组织。 现在我需要列出我所有的人,以及组织的名称。 我不希望Person-entity上有完整的Organization-entity,而只是名称。 像这样: [{ “guid”: “xxx”, “firstName”: “Name”, “organisationGuid”: “yyy”, “organisationName”: “Name of yyy” }] 我怎样才能以最简单的方式实现这一目标? 我已经尝试过的事情: […]

Spring集成出站网关希望像动态一样使用URL

spring集成,在outbound-gateway中想要像动态一样使用URL Requestvalues就像这样简单的POJO @Data public class Requestvalues { public String Url; public String reqMethod; } org.springframework.beans.factory.BeanCreationException:创建名为’org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0’的bean时出错:无法创建[org.springframework]类型的内部bean’(内部bean)#6ea2bc93’。使用key [url]设置bean属性’uriVariableExpressions’时的integration.config.ExpressionFactoryBean]; 嵌套exception是org.springframework.beans.factory.BeanCreationException:创建名为’(内部bean)#6ea2bc93’的bean时出错:通过构造函数的Bean实例化失败; 嵌套exception是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.integration.config.ExpressionFactoryBean]:构造函数抛出exception; 嵌套exception是java.lang.IllegalArgumentException:expressionString不能为空或null

Spring Security将URL参数传递给Authentication Provider

有没有办法将URL参数传递给Spring Security 3中的身份validation提供程序? 我们的登录页面需要接收电子邮件令牌作为身份validation系统在设置用户状态时需要注意的参数。 具体来说,它将允许具有正确令牌登录的用户无法以其他方式登录。 我有一个扩展DaoAuthenticationProvider类的自定义类。 我的身份validation逻辑在该类的身份validation方法中。 我希望有一些方法可以将这些数据传递给authenticate方法。