Tag: spring mvc

SpringMVC Jackson2HttpMessageConverter定制不起作用

我想使用自定义JsonSerializer来实现SpringMVC4的JSON响应。 为了添加JsonSerializer,我创建了WebMvcConfigurerAdapter子类。 但是MappingJackson2HttpMessageConverter的定制不起作用。 简化问题,我尝试了setJsonPrefix。 但它也没有用。 答复没有改变。 我的代码如下。 请告诉我有什么问题。 ControllerClass @Controller public class SampleController { @RequestMapping(“/sample”) @ResponseBody public ResponseModel action() { return new ResponseModel(); } public static class ResponseModel { public String id = “001”; public String text = “aaa”; } } 组态 @Configuration @EnableWebMvc public class WebMvcConfiguration extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters(List<HttpMessageConverter> converters) […]

如何在Spring-mvc中使用html链接调用控制器?

我有一个名为reports.jsp的jsp页面,我在视图中显示了链接,供用户点击。 如何通过单击将传递参数的链接来调用Spring控制器方法。

解释这个Spring MVC Controller的行为

我有这堂课: @Component @Scope(“session”) @Entity @Table(name = “users”) public class User { @Id @GeneratedValue @GenericGenerator(name = “incremental”, strategy = “increment”) private Long userID; @Column(nullable = false) private String username; @Column(nullable = false) private String email; @Column(nullable = false) private String password; // getters and setters } 而这个控制器: @Controller @SessionAttributes(“user”) @Scope(“request”) public class UserCreationWizard { @Autowired private […]

有没有关于Spring MVC vs Struts 2和其他框架的使用情况的统计数据?

我正在对基于请求的Web应用程序框架进行分析,以确定哪一个最适合特定项目,并且我被要求包含一些可靠的证据表明我们的选择被广泛使用和支持构架。 有没有关于此事的统计数据? 甚至是一个使用每个或哪些的主要公司的名单?

保护基于Spring消息传递的websocket服务

我现在正在研究这个问题已有3个星期没有真正的解决方案,我真的希望你能帮助我。 一点项目背景: 使用基于JavaScript / PHP的客户端的Webapp通过SocksJS发送消息并向“门”发送消息 门是用Java / Spring编写的,使用@SendTo和@MessageMapping来发送和接收消息 来自门的消息被发送到RabbitMQ并通过“messageBrokerRegistry.enableStompBrokerRelay”返回给客户端 到目前为止它的工作原理,发送的消息都会回来。 现在是高级安全部分: 消息应该通过包含用户和东西的cookie来保护…… 据我所知,WebSockets本身并不支持安全性。 您必须像使用BASIC auth或类似的“常用”webapp一样保护您的webapp。 所以我添加了一个servletfilter,其中包含一个扩展GenericFilterBean的类。 如果用户发送了正确的cookie页面加载,否则他会收到403错误。 现在出现了问题: 由于@SendTo向所有订阅者发送消息而@SendToUser似乎只将其发送到一个会话,因此我倾向于使用@SendToUser。 但似乎无法选择要创建的rabbitMQ队列。 我想要一些像“/ myqueue-user-123”。 @SendToUser无法做到这一点,因为生成的队列是随机的,并且基于SessionID,我无法覆盖。 所以我尝试过(我尝试除了拦截器,事件等之外的其他东西),使用@SendTo没有值,以便客户端可以决定它必须发送到的队列。 我现在需要的是评估cookie中的用户与“/ myqueue / user-123”相关联。 如果不是,请不要向他发送消息。 阻止他订阅。 断开他,无论如何。 但在我看来,你绝对不能 – 阻止发送消息,只是“拦截”以记录它们而不是改变 – 断开websocket因为它自动尝试重新连接 – 抛出exception,因为订阅仍然继续(事件只是事件,不是要干涉的东西)。 我会非常感谢任何建议或提示。 因为我完全被困在这里……

找不到带URI的HTTP请求的映射(spring 4.1 annotation配置)

首先,请不要锁定这个post。 我已经阅读了所有问题,但仍然无法解决我的问题。 我正在研究如何在spring上使用注释而不配置xml文件。 我正在坚持这个错误: 在DispatcherServlet中找不到具有URI [/WEB-INF/index.jsp]的HTTP请求的映射,其名称为“dispatcherServlet” 这是项目结构 这是我的pom.xml 4.0.0 com.mycompany spring-sample 1.0 war spring-sample ${project.build.directory}/endorsed UTF-8 org.springframework.boot spring-boot-starter-parent 1.2.0.M2 javax javaee-web-api 7.0 provided org.springframework spring-context org.springframework.boot spring-boot-starter-web spring-milestones Spring Milestones http://repo.spring.io/milestone false spring-snapshots http://repo.spring.io/snapshot spring-milestones http://repo.spring.io/milestone org.apache.maven.plugins maven-compiler-plugin 3.1 1.7 1.7 ${endorsed.dir} org.apache.maven.plugins maven-war-plugin 2.3 false org.apache.maven.plugins maven-dependency-plugin 2.6 validate copy ${endorsed.dir} true javax javaee-endorsed-api […]

Spring @Scheduler正在执行两次。 我正在使用spring security,如果我删除上下文参数spring安全性不起作用

我在我的应用程序中使用spring Scheduler和spring security。 如果spring-servlet.xml文件在上下文参数中分配,则spring安全工作正常,但Spring Scheduler执行两次。 安全的context.xml <!– –> 为spring-servlet.xml com.joseph.model org.hibernate.cfg.AnnotationConfiguration ${jdbc.dialect} true 调度程序类 package com.joseph.cronJob; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class SampleCronJobImpl implements SampleCronJob { private static int count=0; @Override @Scheduled(cron = “0 */1 * * * *”) public void testSchedulerfunction() { count++; System.out.println(“scheduler fuction call count: “+count); } } web.xml中 CRUDWebAppMavenizedold log4jConfigLocation […]

Spring MVC中的Response.Clear和Response.ClearContent

我需要知道Spring MVC中的Response.Clear和Response.ClearContent是什么。

使用spring mvc进行静态内容渲染

我是新手,我正在尝试它。 我有一个jsp文件,其中包括css和图像如下 现在我有一个url路径作为/localhost/myapp/test/tst ,它被映射到一个控制器,然后转发它来查看jsp view.jsp出现了 /web-inf/jsp/view.jsp 但是当命中路径/localhost/myapp/test/tst ,css和images路径被解析为 /localhost/myapp/test/tst/css/style.css 我希望它来自/localhost/myapp/css/style.css css和html存在于webapp的根目录中 我如何跟随我的春季配置

Spring-boot ErrorPage不能与独立的Tomcat一起使用

我仍然在努力让Spring-boot错误页面完全在一个带有部署WAR文件的独立tomcat中运行。 我有一个配置类如下: @Configuration @ComponentScan @EnableAutoConfiguration(exclude = [ GroovyTemplateAutoConfiguration, SecurityAutoConfiguration, ErrorMvcAutoConfiguration, JmxAutoConfiguration ] ) class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder application ) { application.sources( Application ) } 并且我的error handling配置如下: @Configuration class ErrorConfiguration implements EmbeddedServletContainerCustomizer { @Override public void customize( ConfigurableEmbeddedServletContainer container ) { container.addErrorPages(new ErrorPage( HttpStatus.NOT_FOUND, “/errors/404” )) } 这个信息似乎得到了使用,但并不像我期望的那样 – 如果我只是去一个不存在的URL然后我得到tomcat默认的404页面 […]