Tag: spring mvc

CSS在春季安全

我应该将CSS添加到登录后访问它的两个页面,其中使用spring security检查数据 如何将CSS添加到受spring security保护的这两个页面? task.jsp <link rel="stylesheet" href="” type=”text/css”> <link rel="stylesheet" href="” type=”text/css”> <link rel="stylesheet" href="” type=”text/css”> <link rel="stylesheet" href="” type=”text/css”> <link rel="stylesheet" href="” type=”text/css”> <link rel="stylesheet" href="” type=”text/css”> 的dispatcherServlet.xml 弹簧security.xml文件

当组件作为会话作用域时,无法将Spring控制器作为请求范围

我正在尝试按照本网站上的指南来正确地将我的bean用于Spring网络应用程序: http://richardchesterwood.blogspot.com/2011/03/using-sessions-in-spring-mvc-including.html 我正在尝试遵循方法3,这基本上意味着我想将我的组件类作为会话范围,因此我必须根据请求调整我的控制器类的范围。 我将控制器放入我的JSP页面,以便可以使用它。 但是,当我尝试这样做时,我的webapp存在构建问题,当我尝试访问网页时,它给出了503 service_unavailable错误。 构建错误是: 严重:上下文初始化失败org.springframework.beans.factory.BeanCreationException:创建名为’org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0’的bean时出错:bean的初始化失败; 嵌套exception是java.lang.IllegalStateException:无法将处理程序’currentWeekController’映射到URL路径[/ TimeTracking]:已经映射了处理程序’scopedTarget.currentWeekController’。 这是相关的类和jsp页面。 如果您还有其他需要,请随便询问! CurrentWeekController控制器类: package controllers; import javax.servlet.http.HttpServletRequest; import models.CurrentWeek; import models.ModelMap; import models.User; import org.joda.time.MutableDateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; /** * this is the controller for current week, it lets you change the current week […]

在使用Spring MVC和Spring Security @PreAuthorize注释时,是否可以知道URL是否可访问?

在我们的Web项目中,我们使用的是Spring security 3.2.3.RELEASE和Spring MVC(以及其他Spring的东西)4.0.5.RELEASE。 我们的控制器方法注释如下: @RequestMapping(value = “/register”, method = RequestMethod.GET) @PreAuthorize(“hasRole(‘ROLE_MANAGER’)”) public String register() { 我的问题是,如果我的用户可以打电话,我是否可以提出弹簧安全问题 http://localhost:8080/project/register 主要目标是在呈现URL之前开发一个要调用的元数据,这样如果用户无法访问此URL,系统就不会呈现它。 我用JSF和Spring Security开发了类似的方法: @Autowired private WebInvocationPrivilegeEvaluator webInvocationPrivilegeEvaluator; public boolean allowedForAction(String action) { log.debug(“Checking action/url:” + action); Authentication a = SecurityContextHolder.getContext().getAuthentication(); NavigationCase nc = ((ReloadAfterNavigationFix) FacesContext.getCurrentInstance().getApplication() .getNavigationHandler()).getNavigationCase(FacesContext.getCurrentInstance(), null, action); if (nc != null) { return webInvocationPrivilegeEvaluator.isAllowed(nc.getToViewId(FacesContext.getCurrentInstance()), a); } […]

Spring Context init(java)

我是spring的初学者,我遇到了基本的上下文初始化问题,我找不到任何简单的教程。 所以我想做的是基本的dependency injection,我已经看到我只需要将类标记为@Componant或@Service,并使用@Autowired直接将它们注入目标fiels中。 为此,我需要正确设置我的spring上下文(我需要构建一个Web服务+使用JPA,所以我想构建一个webapp) 我正在使用JDK 1.8,maven 3.2.1 我想做一个基本的dependency injection。 =>我想在那里注入一个storeImpl实例,但这会导致空指针exception=>这项工作完全没有注入(私有商店storeImpl = new storeImpl();) package com.mycompany.app.controller; @Controller public class Controller { @Autowired private Store storeImpl; public void use() { storeImpl.get(); } } package com.mycompany.app.store; public interface Store { boolean get(); } package com.mycompany.app.store; @Component public class StoreImpl implements Store { @Override public boolean get() { return […]

在Spring Boot服务上运行有限数量的线程

我目前正在使用spring boot开发一个Web应用程序,我在服务层中遇到了问题。 我的服务层上有一个沉重的方法。 如果多个用户调用相同的服务,则应用程序会因内存不足而停止。 所以我想限制该方法的并行运行线程的数量。 到目前为止,我已经出现了在该方法上使用synchronized 。 但它会将它限制为单线程方法。 @Service public class DocumentService{ private synchronized void doReplacement(){ //should have limited no of multi threads (eg. 3) } private void normalMethod(){ //no restrictions } } 我该怎么做才能完成这项任务。 任何帮助,将不胜感激。

如何在spring mvc拦截器中validation会话

我是spring framework的新手。在我的代码中,我使用拦截器检查会话是否存在。如果会话存在,我允许调用控制器,否则我重定向登录页面。 以下是我的代码。 @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Users user=(Users) session.getAttribute(“user”); if(user == null) { System.err.println(“Request Path : “); response.sendRedirect(“index”); return false; } else { return true; } } 但是这段代码没有成功重定向。我收到以下错误, In Mozilla i get below error The page is not redirecting properly In chorme i get below error? This web page has redirect […]

Spring mvc @DateTimeFormat无法按预期工作

我刚刚在jsp中制作的简单页面中添加了一个jQuery日期选择器。 使用Spring mvc 4.0.0。 我想在我的模型类中有java.util.Date字段,让spring将日期String从前端转换为日期。 我的问题是,如果我有 @DateTimeFormat(pattern = “dd/MM/yy”) private Date startDate; 在我的模型类中,我在spring控制器中收到null值。 (startDate setter既不被调用)如果我将startDate更改为一个简单的String,那么正确填充该值并且在控制器中我能够检索startDate字符串。 你能告诉我我错过了什么吗? 试图按照http://gerrydevstory.com/2013/05/21/binding-date-form-input-on-spring-mvc/似乎没有使用其他技巧将String转换为Date。

Group By:Spring JPA规格

我正在尝试使用Spring Data JPA规范,并想知道如何在规范中使用Group By 。 请参阅下面我当前的规格: 知识库 public interface OauthAccessTokenRepository extends JpaRepository, JpaSpecificationExecutor { } 规格 public class OauthAccessTokenSpecification { public static Specification equalsTokenId(final String tokenId) { return new Specification() { public Predicate toPredicate(Root root,CriteriaQuery query, CriteriaBuilder cb) { return cb.equal(root.get(“tokenId”), tokenId); } }; } public static Specification equalsRefreshToken(final String refreshToken) { return new Specification() […]

无知我在设置Spring Boot REST应用程序时遇到了什么问题

在设置我认为是一个简单的Spring Boot Rest api的时候,我一直很困惑我做错了什么。 我确实有建立非常基本的春季应用程序(仍然是学生)的经验,但这是我第一次设置一个Spring Rest应用程序。 我确实在基本文件夹中有应用程序,应用程序似乎启动但是当我转到“localhost:8080 /”时出现404错误。 我假设也许我的pom不正确。 我注意到我的打印跟踪没有显示正在暴露的存储库。 谢谢你的帮助。 主要: @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } } BaseEntity: @MappedSuperclass public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private final Long id; protected BaseEntity() { id = null; } } 实体: @Entity public class Course […]

请求Content-Type为gzip时,Jetty会响应400 Bad Request

在Jetty 9.3.0.v20150612上运行的Spring MVC Java 1.8.0_45-b14后端适用于未压缩的请求,但无法接受压缩的请求。 我在这里遵循了Gzip Handler配置说明,确保它们也支持POST请求。 虽然它没有说这种配置完全适用于请求……但它可能仅用于响应。 etc / jetty-gzip.xml – GET POST /* 在web.xml中 – GzipFilter org.eclipse.jetty.servlets.GzipFilter mimeTypes text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml,application/json minGzipSize 500 GzipFilter /* Android客户端会发生这种情况,并且还会使用HTTP客户端应用程序(Paw)进行重现,这是一个请求示例 – POST /report?v=1 HTTP/1.1 Content-Encoding: gzip Content-Type: application/json Host: 10.0.0.1:8080 Connection: close User-Agent: Paw/2.2.2 (Macintosh; OS X/10.10.4) GCDHTTPRequest Content-Length: 5845 xí\MÇuÝûWÔE(É`_¦(<EtD&)%:¦OTè.EôÔU53¬¼ð"ÇYfÆ'®ì/áÿʽ¯ª r(ʲä#èúz÷Ý÷^5èýR;Úå;ÕÎÿöºÊuW«ß«v«ß¿ø³:VÕ)Õ .. BINARY … 回应 – HTTP/1.1 400 […]