据我所知: PUT – 用其整个表示更新对象(replace) 修补程序 – 仅使用给定字段更新对象(更新) 我正在使用Spring来实现一个非常简单的HTTP服务器。 当用户想要更新他的数据时,他需要为某个端点(比如: api/user )创build一个HTTP PATCH 。 他的请求体通过@RequestBody映射到DTO,如下所示: class PatchUserRequest { @Email @Length(min = 5, max = 50) var email: String? = null @Length(max = 100) var name: String? = null … } 然后我使用这个类的一个对象来更新(修补)用户对象: fun patchWithRequest(userRequest: PatchUserRequest) { if (!userRequest.email.isNullOrEmpty()) { email = userRequest.email!! } if (!userRequest.name.isNullOrEmpty()) { name […]
我希望每个请求都能得到一些信息,所以我认为不是每个请求都有一个函数,而是分别从请求中获取这些信息, 最好是有一个filter。 所以每一个请求都要通过这个filter,我得到我想要的。 问题是:如何编写自定义filter? 假设它不像任何预定义的弹簧安全filter,它是全新的。
我为一个简单的REST API使用Spring Boot,并希望在出现问题时返回正确的HTTP状态码。 @RequestMapping(value="/rawdata/", method = RequestMethod.PUT) @ResponseBody @ResponseStatus( HttpStatus.OK ) public RestModel create(@RequestBody String data) { // code ommitted.. // how do i return a correct status code if something fails? } 作为Spring和Spring Boot的新手,基本的问题是,当某些事情是好的或者失败的时候,我如何返回不同的状态代码?
什么使模块/服务/应用程序function成为OSGi模块的特别好select? 我有兴趣在我的应用程序中使用OSGi 。 我们是一个Java商店,我们广泛使用Spring,所以我倾向于使用OSGi(tm)服务平台的Springdynamic模块 。 我正在寻找一种将OSGi稍微join到应用程序中的好方法。 有没有人在这里使用过这个或类似的OSGi技术? 有什么陷阱吗? @尼古拉斯 – 谢谢,我已经看到了一个。 这是一个很好的教程,但我正在寻找更多关于如何做我的第一个“真正的”OSGi包,而不是一个Hello World示例的想法。 @david – 感谢您的链接! 理想的情况是,在一个绿色的应用程序,我会devise整个事情是dynamic的。 但是,我现在要找的是将其引入现有应用程序的一小部分。 假设我可以select任何应用程序,有什么因素可以使OSGi豚鼠变得更好或更糟?
有没有办法在XML中编写Spring bean,以便在构造函数具有可变参数types时使用构造函数注入? IE,有没有一种方法来指定一个数组的方式,你可以指定一个列表? 例如: class MyClass { MyClass(String… args) { // rest omitted } }
我在我的项目中有三个模型对象之间的关系(模型和存储库代码片尾) 当我打电话PlaceRepository.findById它会触发三个select查询: ( “SQL”) SELECT * FROM place p where id = arg SELECT * FROM user u where u.id = place.user.id SELECT * FROM city c LEFT OUTER JOIN state s on c.woj_id = s.id where c.id = place.city.id 这是非常不寻常的行为(对我来说)。 据我所知,在阅读Hibernate文档后,应该总是使用JOIN查询。 当FetchType.LAZY更改为Place类中的FetchType.EAGER (具有附加SELECT的查询)时,查询在查询中没有区别,而当FetchType.LAZY更改为FetchType.EAGER (JOIN查询)时, City类也相同。 当我使用CityRepository.findById抑制两个select: SELECT * FROM city c where id = […]
我现在无法连接到我的web服务在Android上。 我使用jackson-core / databind / annotation-2.2.4和Spring RESTWebService。 如果我从浏览器访问URL,我可以看到JSON响应:(服务器返回List \ Shop \看起来像:) [{"name":"shopqwe","mobiles":[],"address":{"town":"city", "street":"streetqwe","streetNumber":"59","cordX":2.229997,"cordY":1.002539}, "shoe" [{"shoeName":"addidas","number":"631744030","producent":"nike","price":999.0, "sizes":[30.0,35.0,38.0]}] 从客户端端点(Android应用程序),我收到此错误消息: 08-26 17:43:07.406: E/AllShopsAsyc(28203): Could not read JSON: Can not deserialize instance of com.auginzynier.data.ShopContainer out of START_ARRAY token 08-26 17:43:07.406: E/AllShopsAsyc(28203): at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41efbd48; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.auginzynier.data.ShopContainer out […]
我有一个使用JPA加载和保存域对象的DAO。 我终于设法得到交易的东西工作,现在我有另一个问题。 在我的testing案例中,我打电话给我的DAO加载一个给定id的域对象,检查它是否被加载,然后调用相同的DAO删除刚加载的对象。 当我这样做时,我得到以下内容: java.lang.IllegalArgumentException: Removing a detached instance mil.navy.ndms.conops.common.model.impl.jpa.Group#10 at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:45) at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:108) at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74) at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794) at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772) at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:253) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:180) at $Proxy27.remove(Unknown Source) at mil.navy.ndms.conops.common.dao.impl.jpa.GroupDao.delete(GroupDao.java:499) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) […]
我有一个基于代码的configuration的Spring 3.2.4 Web应用程序。 当我使用Maven / pom.xml首先构build应用程序时,出现web.xml缺失的错误。 首先我试图创build一个空的web.xml。 这是项目方面改变的时刻(我不知道为什么)。 它从dynamicWeb模块3.0切换到3.1,这是不可逆转的。 我怎样才能改变到dynamic网页模块3.0? 另外我不能删除JAX-RS。 尝试这个结果是: Failed while uninstalling JAX-RS (REST Web Services) 1.0. org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp 后来我发现我可以通过在pom.xml中插入相应的插件来避免Maven编译错误: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
我正在尝试创build一个Web应用程序,主要是使用Spring提供一个REST API,并试图configuration安全方面。 我试图实现这种模式: https : //developers.google.com/accounts/docs/MobileApps (谷歌已经完全改变了这个页面,所以不再有意义 – 请参阅我在这里指的页面: http: //web.archive.org/web/20130822184827/https://developers.google.com/accounts/docs/MobileApps ) 这是我需要实现的: Web应用程序具有简单的login/registry单,可以和普通的spring用户/密码authentication一起工作(之前用dao / authenticationmanager / userdetailsservice等做过这种types的事情) REST API端点是无状态会话,并且每个请求都是基于随请求提供的令牌进行身份validation的 (例如,用户使用常规表单login/注册,webapp提供安全的cookie和令牌,然后可以在以下API请求中使用) 我有一个正常的身份validation设置如下: @Override protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .antMatchers("/resources/**").permitAll() .antMatchers("/mobile/app/sign-up").permitAll() .antMatchers("/v1/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/") .loginProcessingUrl("/loginprocess") .failureUrl("/?loginFailure=true") .permitAll(); } 我正在考虑添加一个pre-authfilter,检查请求中的令牌,然后设置安全上下文(这意味着正常的后续authentication将被跳过?),但是,超出正常的用户/密码我有基于令牌的安全性并没有做太多的事情,但是基于其他一些例子,我提出了以下内容: 安全configuration: @Override protected void configure(HttpSecurity http) throws Exception { […]