编程面试题

  • 在Spring MVC控制器中将自定义验证器应用于多个类

    你可以这样做 public boolean supportsClass clazz { return Registration.class.equalsclazz || Another.class.equalsclazz; } 然后您的验证应执行以下操作 public void validateObject ta

  • 无法在我的Spring Security中使用SHA-256哈希

    最后,我想出了这个解决方案,感谢@Oleg Estekhin的评论: public String sha256String original throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance"SHA-256"; md.updateoriginal.getBytes;

  • Spring io @Autowired:空白的final字段可能尚未初始化

    在@Autowired球场上拥有和决赛是矛盾的。 后者表示:此变量只有一个值,并且在构造时初始化。 前者说:Spring将构造对象,将此字段保留为空(其默认值)。然后,Spring将使用反射类型为WorkspaceRepository的bean初始化此字段。 如果要自动绑定最终字段,请使用构造函数注入,就像您自己进行注入一样: @Au

  • 无法自动连线org.springframework.mail.javamail.JavaMailSender

    根据mserioli的评论,答案是必须在根调用的配置文件中声明Bean。 在这种情况下:移动 @Bean public JavaMailSenderImpl mailSender 至 public class ExtraConfig { @Bean public JavaMailSenderImpl ma

  • 单元测试通过Maven,但未通过Cobertura:“预期分支目标65处的堆栈映射框架”

    当然,即使我之前搜索了很长时间,我也会在问了问题后立即找到答案… 问题在于Cobertura在使用Java 1.7时遇到了麻烦。您必须将以下行添加到pom.xml中: argLine-XX:-UseSplitVerifierargLine 那在配置元素中。这是整个Cobertura部分:

  • 使ServletContextListener弹簧感知

    好, 我们有一个类似的方案,将现有的 Jersey Web服务应用程序配置为使用 Spring 进行依赖项注入。我们的 Jersey网络 应用扩展了 ContextLoaderListener ,如下所示 public class XServle

  • 有没有办法在Spring MVC Test中使用AssertJ断言?

    更新资料 如果您想投票支持对AssertJ断言的支持MockMvc,请参阅相关的Spring JIRA问题:SPR-16637。 一般来说,在使用Spring进行测试时,您可以选择喜欢的任何断言框架。

  • Dart:将所有带引号的元素转换为JSON

    import 'dart:convert'; ... json.encodedata; JSON.encodedata in Dart 1.x 总是导致我引用JSON。 你不需要打电话toString

  • 请求映射的默认请求方法类型是什么?

    如果未指定任何映射,则此方法将解析所有http请求,即,您可以将GET,POST,HEAD,OPTIONS,PUT,PATCH,DELETE,TRACE请求发送到指定的url,它将被解析。

  • 如何在Flask应用程序中创建动态子域

    @app.before_request def before_request: if 'api' == request.host[:-lenapp.config['SERVER_NAME']].rstrip'.': redirecturl_for'api' @app.route'', defaults={'path': ''}, subdomain='api' @app.rou

  • Spring Service $ proxy25错误

    您需要针对接口类型而不是类类型自动布线,即 @Autowired ItemsService serviceClass1; 如果您有多个实现的bean ItemsService,那么自动装配并不十分合适。考虑@Resource改用: @Resourcename="serviceClass1"

  • Spring Bean配置等同于

    将对“ ”的请求转发到Java中称为“ home”的视图的示例: @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addViewControllersViewControllerRegistry registry { reg

  • 如何使用GSON / JSON将字符串数组转换为对象?

    这很简单,您只需要执行以下操作: 1.-首先创建Gson对象: Gson gson = new Gson; 2.-然后获取Type您的代理人ListString[](请注意,ListString[].class由于Jav

  • 阻止重定向到Spring Security的登录

    发现了这一点:always-use-default-target =“ true” 通过这种方式,我的控制器功能总是在任何登录后被调用。

  • 通过Spring MVC在REST服务中将对象转换为JSON

    最终,我得到了使用Jackson库和Spring MVC的解决方案。我从Journal Dev(a href="http:www.journaldev.com2552spring-restful-

  • Spring MVC 3:发现模糊映射

    如果你有一个控制器,如下面给出的,比其他所有的请求bookedit将被引导到mydefault,而bookedit将被发送到meet。 @Controller @RequestMapping"book" public class BookController { @Request

  • 服务中的Spring @Async方法

    我解决了第三个方法(将其分为两个Bean),将Async方法修改器切换为 public @Service public class MyService { @Autowired MyAsyncService myAsyncService; public worker{ myAsyncService.asyncJob; } }

  • 如何使用注解而不是XML定义Spring bean?

    有关于此的文档。您将需要类似的构造型注释@Component。 构造型bean注释 div

  • 如何使fmt:formatDate用于form:input

    您不能在另一个JSP标签的属性中使用JSP标签。将日期格式的结果存储在page属性中,并使用此page属性(就像对Java中的变量所做的那样): fmt:formatDate value="transactions['${loopStatus.index}'].valueTransactionDate" type="date" patt

  • 如何在Spring MVC中代理HTTP请求?

    看起来当大小变得太大时,远程服务器会以分块响应进行响应,Apache HttpClient库将所有分块元素收集在一个大的HttpResponse中,但是保留了Transfer-Encoding: chunked标头。 我无法测试,但是您应该过滤掉Transfer-Encoding: chunked来摆脱此问题: private

  • 使用注释时模拟Spring MVC BindingResult

    BindingResult是一个接口,所以您不能简单地传入该接口的Springs实现之一吗? 我在Spring MVC代码中不使用注释,但是当我想测试验证器的validate方法时,我只是传入BindException的实例,然后使用在assertEquals等中返回的值。

  • 拦截模块调用?

    在renderer.py: import sys if __name__ != "__main__": sys.modules[__name__] = OpenGLRenderer 现在,模块名称已映射到OpenGLRenderer实例,并且import renderer在其他模块中将

  • Spring MVC InterceptorHandler用DeferredResult调用了两次

    您需要使用org.springframework.web.servlet.AsyncHandlerInterceptor: public interface AsyncHandlerInterceptor extends HandlerInterceptor { void afterConcurrentHandlingStarted HttpServl

  • 一起测试Spring asyncResult()和jsonPath()

    Bud的回答确实帮助我指出了正确的方向,但是由于它没有等待异步结果,因此并没有奏效。自发布此问题以来,spring-mvc- showcase示例(https:github.comSpringSo

  • 使用Spring MVC,接受JSON错误的POST请求会导致返回默认的400错误代码服务器页面

    这是Spring的一个问题SPR-7439-JSON(jackson)@RequestBody编组抛出尴尬的异常- 在Spring 3.1M2中已通过org.springframework.http.converter.HttpMessageNotReadableExcept

  • Spring将内容保留在内存中还是存储在磁盘中?

    在Javadoc中进行的更多挖掘显示,默认的最大内存大小为10240字节。据此,我假定任何小于10

  • 如何在Spring中将RequestHeader转换为自定义对象

    基本上我已经完成了评论中的建议。我将仅提供简短示例。假设我们有下一个控制器和用户POJO: import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.anno

  • 在Thymeleaf中格式化th:field

    我错过了简单的答案,仅仅是因为我对Spring的了解有限。我在这里添加它,以防它对像我这样的任何其他新手有所帮助。在@DateTimeFormat传递中的对象的元素注释的形式做这项工作。它可以确保Date按照您希望的方式格式化对象(无论是否使用Thymeleaf)。 在上面的示例中,在bookingEntry对象中 @

  • Spring拦截器与Servlet过滤器

    您可以在拦截器中注入其他bean 您可以使用更高级的映射模式(蚂蚁风格) 您具有可用的目标处理程序对象(控制器)以及结果 ModelAndView 它是一个bean,因此您可以将其与AOP一起使用(尽管这种情况很少见)

  • 在Spring MVC REST中返回文件

    下面的代码解决了我的问题: @RequestMappingvalue = URIConstansts.GET_FILE, produces = { "applicationjson" }, method = RequestMethod.GET public @ResponseBody ResponseEntity getFile@RequestParamvalue="fileName", require

  • Spring MVC中的多个响应http状态

    有人在SO上建议的一种方法是引发不同的异常,这些异常将被不同的异常处理程序捕获: @RequestMappingvalue = "systemlogin", method = RequestMethod.GET public void login@RequestBody Login login { iflogin.username == "test" login.pa

  • spring-form.tld…在哪里?

    在中spring-webmvc-3.0.x.RELEASE.jar,当然。

  • Spring验证异常:BindException

    在控制器的addUser方法中,您BindingResult需要紧接在bean之后: public String addUser@Valid UserBean userBean, BindingResult bindingResult, Model model, RedirectAttributes redirect

  • 分页不接受dict作为数据-不可散列的类型

    tuple改为使用dict,如下所示: # convert `dict` to `tuple`: prodmatrix = tupleprodmatrix paginator = Paginatorprodmatrix, 2 # or this paginator = Paginatorprodmatrix.items, 2 page = re

  • 如何在Spring中将对象添加到应用程序范围

    基本上,配置应用程序作用域所需的全部就是使用ServletContext,您可以在Spring中按如下所示进行操作: public class MyBean implements ServletContextAware { private ServletContext servletContext; public void setServletContextServ

  • Spring MVC“复制” URL的一部分

    我想这与默认视图名称解析有关。 如果要将处理程序方法返回的值编码为响应主体(在JSON,XML等中),则需要使用注释该方法@ResponseBody,或使用@RestController(在Spring 4.x中)注释整个控制器。 否则,Spring将尝试使用您的return作为模型属性来渲染视图。并且由于您没有提供要渲染的视图的名称,因此Sp

  • 将JSR-303验证错误转换为Spring的BindingResult

    一个更简单的方法可能是使用Spring的抽象org.springframework.validation.Validator,您可以通过在上下文中包含此bean来获得验证器: bean id="jsr303Validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBea

  • 想要创建一个过滤器以检查Cookie,然后保存控制器中的对象和引用

    要创建过滤器,只需创建一个实现javax.servlet.Filter的类,就您而言,可能是这样 public class CookieFilter implements Filter { public void doFilterServletRequest req, ServletResponse res, FilterChain chain throws I

  • spring父上下文和子上下文之间有什么区别?

    Spring的bean在应用程序上下文中运行。 Application Context是Spring的高级容器。与BeanFactory相似,它可以加载Bean定义,将Bean连接在一起,并根据请求分配Bean。此外,它增加了更多企业特定的功能,例如从属性文件解析文本消息的功能以及将应用程序事件发布到感兴趣的事件侦听器的功能。该容器由org.springframework.context.

  • Spring SAML扩展和Spring Security CSRF保护冲突

    您至少有两个选择。 一种是实现自定义RequestMatcher(org.springframework.security.web.util.RequestMatcher),该自定义()在Spring SAML URL上将不匹配,并将其通过以下方式提供给csrf配置: http.csrf.requireCsrfProtect