Tag: spring mvc

为什么jackson2不承认第一个大写字母,如果领先的骆驼案例字只有一个字母长?

我正在使用Spring 4 MVC和Jackson 2进行我的服务。 对于其中一个操作,我有一个请求对象,该对象具有一个属性,其中前导驼峰字的长度只有一个字母: private String aLogId; 这个类有适当命名的getter和setter: public String getALogId() { return aLogId; } public void setALogId(String aLogId) { this.aLogId = aLogId; } 但是,当我尝试使用相应的JSON属性向此服务发布请求时: {“aLogId”:”This is a log id”} 我收到Spring框架的500响应,说该字段无法识别,我的控制器类永远不会被调用: 无法读取JSON:无法识别的字段“aLogId”(类 但是,当我将“L”更改为小写时,请求按预期反序列化并且我的控制器类被命中: {“alogId”:”This is a log id”} 为什么jackson期望“L”是小写的,因为它显然是该属性的驼峰案例约定中的第二个单词并且意图是大写的? 是因为第一个单词只有一个字母长吗? 请求对象中还有其他属性,其中第一个单词不止一个字母,并且那些属性不会遇到同样的问题,并且情况不匹配。

使用hibernate正确使用Spring mvc 3(Spring ORM)

我正在开始一个新项目,这次尝试做正确的事情(所以不止一个问题),我可能需要一些帮助,我不确定我做错了什么: spring的背景 调节器 服务接口 服务实施 DAO接口 DAO实施 我想尽可能多地使用spring MVC,如何通过@Transactional处理会话打开/关闭? 如何捕获exception(即非现有记录或数据库失败)(如果有)。 即我的数据库不接受像这样的重复条目: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 我怎么能抓到这个? 对于我提出的每个下一个请求,我都会遇到此exception: org.hibernate.AssertionFailure: null id in com.test.spring.ws.service.impl.TestObject entry (don’t flush the Session after an exception occurs) 我做错了什么? 有人可以建议我的项目有一些改进吗?

ApplicationContext和ServletContext

当谈到Spring MVC Application时,我对两个ApplicationContext和ServletContext感到困惑。 我知道每个Spring Web应用程序只有一个ApplicationContext,每个Web应用程序也只有一个ServletContext。 要在web.xml中启动ApplicationContext和ServletContext的值,我们将在context-param标记中添加一些内容。 这让我感到困惑。 这两者之间有什么区别 (我知道ApplicationContext有一些使用bean的方法)? 当我们使用ApplicationContext 时何时使用ServletContext ?

JSON,泽西岛和jackson的多态性

Jackson和Jersey支持多态类而不是JSON吗? 比如说,我有一个Parent类和一个inheritance它的Child类。 而且,假设我想使用JSON通过HTTP发送和接收父和子。 public class Parent { … } public class Child extends Parent { … } 我考虑过这种实现: @Consumes({ “application/json” }) // This method supposed to get a parent, enhance it and return it back public @ResponseBody Parent enhance(@RequestBody Parent parent) { … } 问题:如果我给这个函数(当然是通过JSON)一个Child对象,它会起作用吗? 孩子的额外会员字段也会被序列化吗? 基本上,我想知道这些框架是否支持多态消费和响应。 顺便说一下,我正在使用Spring MVC。

Thymeleaf的Spring Security简单示例

嗨,我正在尝试按照一个简单的例子来做一个简单的登录表单页面,我在这个页面中找到http://docs.spring.io/autorepo/docs/spring-security/4.0.x/guides/form.html 问题是我每次尝试登录时都会收到此错误我收到此错误: Expected CSRF token not found. Has your session expired? Expected CSRF token not found. Has your session expired? 当我收到此错误时,我按下浏览器中的后退按钮并尝试第二次登录,当我这样做时,我收到此错误: HTTP 403 – Invalid CSRF Token ‘null’ was found on the request parameter ‘_csrf’ or header ‘X-CSRF-TOKEN’ 在教程页面中是这条消息: We use Thymeleaf to automatically add the CSRF token to our form. If we were not […]

servlet映射url-pattern上的双通配符(*)是什么意思?

我想知道使用单个或双通配符来描述servlet映射上的url模式有什么不同。 例如:下面有什么区别? 1) BuyServlet /buy/* 2) ShopServlet /shop/** 编辑:@Andrew是对的,规范只讨论一个通配符(*)。 我仔细检查了我的代码并注意到我找到双通配符(**)的地方是在Spring SimpleUrlHandlerMapping bean中。 在这种情况下,它是有道理的。 根据类doc ,它使用AntPathMatcher ,它指出: 映射使用以下规则匹配URL: 匹配一个字符*匹配零个或多个字符**匹配路径中的零个或多个“目录”

Spring JPA(Hibernate)没有类型的限定bean:javax.persistence.EntityManagerFactory

我正在使用Spring-boot,因此在Tomcat 7中部署了一场战争。当我启动应用程序时,我得到以下内容: Dec 30, 2013 7:41:06 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet ‘dispatcherServlet’ 2013-12-30 19:41:06 INFO DispatcherServlet:461 – FrameworkServlet ‘dispatcherServlet’: initialization started 2013-12-30 19:41:06 INFO SimpleUrlHandlerMapping:315 – Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2013-12-30 19:41:06 INFO RequestMappingHandlerMapping:181 – Mapped “{[/user],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}” onto public com.cloudfordev.controlpanel.orm.User com.cloudfordev.controlpanel.GetController.getUser(int) 2013-12-30 19:41:07 INFO SimpleUrlHandlerMapping:315 – Mapped […]

在单个服务器上运行带有Angular 2的Spring4MVC

我是angular2的新手,我想知道SpringMVC4的角度为2的可能文件结构是什么? 如图所示,它适用于Angular 1.x,但Angular 2的文件结构完全不同,其组件驱动,我使用的是角度2文件结构,如下所示 我搜索了很多,我发现我们可以分别使用前端(使用angular2)和后端(服务器 – 使用spring / springboot),但我们需要2台服务器来运行应用程序。 例如,前端:192.168.100.1:4200和后端:192.168.100.1:8080 那么在同一台服务器上运行angular2和spring4MVC是否有任何方式或通用文件结构(如192.168.100.1:8080)? 提前致谢。 答案将不胜感激!

Spring MVC自定义方法参数绑定

我正在寻找一种方法来自定义默认的Spring MVC参数绑定。 以此方法为例: @RequestMapping(value=”/index.html”) public ModelAndView doIndex(@RequestParam String param) { … 当我只有一个我想从请求中提取的String ,这很容易。 但是,我想填充更完整的对象,以便我的方法如下所示: @RequestMapping(value=”/index.html”) public ModelAndView doIndex(Foo bar) { … 我正在寻找的是一种声明像这样的绑定的方法; @RequestMapping(value=”/index.html”) public ModelAndView doIndex(@FooPopulator Foo bar) { … 并有一些其他类型的实现者(由@FooPopulator注释确定)执行此操作: public void doBind(Foo target, ServletRequest originalRequest) { target.setX(this.computeStuffBasedOn(originalRequest)); target.sety(y); } 到目前为止,我已经了解了@InitBinder绑定器注释,但我不确定这是否真的是这个场景的正确选择。 什么是最好的方式?

Spring MVC Web应用程序:应用程序上下文启动两次

我正在开发一个Spring MVC REST API。 一切正常,这很好,但我从日志中注意到,每次重新启动应用程序时,applicationContext都会加载两次:一次是tomcat加载war文件,第二次是第一次访问web应用程序时客户。 我举几个例子: 我启动tomcat后: Apr 11, 2013 10:14:35 AM org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.32 Apr 11, 2013 10:14:36 AM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext 2013-04-11 10:14:36 INFO ContextLoader:273 – Root WebApplicationContext: initialization started 2013-04-11 10:14:36 INFO XmlWebApplicationContext:510 – Refreshing Root WebApplicationContext: startup date [Thu Apr 11 10:14:36 […]