Tag: spring

使用Spring Solr数据或不使用灵活请求作为备份?

我想在Spring实现一个与我当前的Solr或SolrCloud交互的应用程序。 我考虑过使用Spring Data Solr。 但是,如果我只运行这样的查询,我认为还没有实现CloudSolrServer: http://localhost:8983/solr/replication?command=backup 并检查备份是否完成(我将执行get请求,解析JSON并将看到上次备份时间是否已更改)如何将其与Spring Data Solr集成? 我的意思是在我的情况下使用Spring + Solrj而不是Spring Data Solr更有意义(那就是我想做更灵活的事情,只有在使用Spring的Solr上进行CRUD操作)?

无法将类型的值转换为所需类型的属性

我正在从jsp保存图像文件并在控制器中重命名它 问题是同一段代码在控制器的一个部分工作,而不在控制器的另一部分工作 这里是jsp代码,在两种情况下都是相同的: – Photo: 以下是控制器按预期工作的部分: – @RequestMapping(value = “/student”, params = “add”, method = RequestMethod.POST) public String postAddStudent(@ModelAttribute @Valid Student student, BindingResult result, Model model) throws IOException { if (result.hasErrors()) { System.out.println(result.getAllErrors().toString()); model.addAttribute(“examination_names”, ExaminationName.values()); ArrayList roles = new ArrayList(); roles.add(Role.STUDENT); model.addAttribute(“roles”, roles); return “student/add”; } else { System.out.println(“Inside postAddStudent”); System.out.println(student); student = studentService.save(student); String […]

将JSON发送并解析为弹簧控制器?

假设,如果我有JSON数据, var json = {“name”:”kite Player”,”age”:”25″,”hobby”:”footbal”} 我可以通过发送JSON数据 var jsonData = JSON.Stringfy(json); 在JQueryAjax , data = jsonData , 我可以解析弹簧控制器中的JSON数据, public class TestController { @RequestMapping(method = RequestMethod.POST, value = “personDetails.html”) public @ResponseBody Result math(@RequestBody final Persons persons) { String name = person.getName(); String age = persons.getAge(); String hobby = persons.getHobby(); // Other process } } 如何在Spring controller解析JSON […]

@RequestMapping的产生对值的顺序敏感吗?

这个问题是基于这个问题 。 通过提供的评论,我编写了三种不同的测试来validation正确设置的内容类型。 @Test public void testGetImageJpg_ShouldSucceed() throws Exception { File testImage = new File(TestConstants.TEST_IMAGE_JPG); byte[] expectedBytes = IOUtils.toByteArray(new FileInputStream(testImage)); when(service.getImage(anyString(), anyString())).thenReturn(testImage); mockMvc.perform(get(“/getImage/id/bla.jpg”).sessionAttrs(session)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(expectedBytes)); } @Test public void testGetImagePng_ShouldSucceed() throws Exception { File testImage = new File(TestConstants.TEST_IMAGE_PNG); byte[] expectedBytes = IOUtils.toByteArray(new FileInputStream(testImage)); when(service.getImage(anyString(), anyString())).thenReturn(testImage); mockMvc.perform(get(“/getImage/id/bla.png”).sessionAttrs(session)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.IMAGE_PNG)) .andExpect(content().bytes(expectedBytes)); } @Test public void testGetImageGif_ShouldSucceed() throws Exception […]

Grails – 为什么需要交易?

首先是一些背景:我使用Spring Security的修改版本来执行Active Directory身份validation,并检查存储在数据库中的可能访问权限。 这意味着在普通的Groovy类中调用从数据库加载信息: if (Holders.config.loadRolesFromDatabase) { Set roles = DomainClassUser.findByUsername(username)?.roles if (roles) authorities.addAll(roles.collect({ new SimpleGrantedAuthority(‘ROLE_’ + it.name) })) } 这在Hibernate 4.3.6.1和Tomcat 7.0.54上运行得很好,但是,在升级它们(到4.3.10.18和8.0.14.1)后,它现在在调用动态查找器时产生“HibernateException:当前线程找不到会话”exception方法。 做了一些研究之后,我决定将这段代码包装在withTransaction块中: if (Holders.config.loadRolesFromDatabase) { DomainClassUser.withTransaction({ Set roles = DomainClassUser.findByUsername(username)?.roles if (roles) authorities.addAll(roles.collect({ new SimpleGrantedAuthority(‘ROLE_’ + it.name) })) }) } 这修复了错误,但是,我不确定为什么这是必需的。 我目前对withTransaction的理解是它用于创建可以在exception情况下回滚的事务等。但是,我不需要在这里执行任何回滚(它只是所有只读调用),为什么我仍然需要一个交易来执行此调用?

即使在SpringMVC中包含密钥库证书后,也无法对服务器进行身份validation

我正在尝试对jira服务器进行身份validation并从服务器获取问题详细信息,这里我最初手动给出id。 我已经下载了服务器证书并使用keytool导入,密码是“密码”到密钥库。 但我无法在下面validation它是我的代码 我的java代码: @Controller public class Service{ @RequestMapping(“/hello”) public String Data(ModelMap model) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, KeyManagementException, UnrecoverableKeyException{ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(“/users/crohitk/Documents/workspace/frr/publicKey1.store”), “password”.toCharArray()); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()) .loadKeyMaterial(keyStore, “password”.toCharArray()).build()); HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); RestTemplate restTemplate = new RestTemplate(requestFactory); […]

尝试访问dao bean时,注入自动连接的依赖项失败

我在访问网页时遇到错误。 这是我的代码 – web.xml文件 – index.jsp dispatcher org.springframework.web.servlet.DispatcherServlet 1 dispatcher / 调度程序servlet的名称 – “dispatcher-servlet.xml” <!– –> com.webProject.model.Student org.hibernate.dialect.MySQLDialect true create none true <!– –> 学生控制class – package com.webProject.controller; @Controller @RequestMapping(“/Student”) public class StudentController { @Autowired private IStudentDao studentDao; //List students; /*public StudentController() { students = new ArrayList(); }*/ public IStudentDao getStudentDao() { return studentDao; } […]

Spring Security OAuth 2,带有表单登录

我正在尝试配置我的Spring启动应用程序以使用表单登录,并使用OAuth 2授权服务器validation凭据(将表单登录中的凭据发送到用户授权URL。 但是,当我使用以下SecurityConfig并且我转到资源时,而不是使用表单登录,它会重定向到授权服务器,询问我的凭据(使用基本身份validation),然后重定向回应用程序本身。 我正在使用以下SecurityConfig : @Configuration @EnableOAuth2Sso public class SecurityConfig extends OAuth2SsoConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { http .logout() .and() .antMatcher(“/**”) .authorizeRequests() .anyRequest().authenticated() .and() .csrf() .csrfTokenRepository(csrfTokenRepository()).and() .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class) .formLogin(); } // CSRF repository + filter } 我将formLogin()提供给configure()方法,但这似乎不起作用。 以下配置位于我的application.yml文件中: spring: oauth2: client: clientId: test clientSecret: secret accessTokenUri: http://localhost:8081/uaa/oauth/token userAuthorizationUri: http://localhost:8081/uaa/oauth/authorize clientAuthenticationScheme: header […]

在MailTo中转义和符号

我有一个这样的URL: http:// localhost:9001 / view / shopindex / display?keyword = test&searchPostcode = Postcode ,我把它放在使用HTML mailTo的新电子邮件正文中(我知道有更好的mailTo的选项,但我只限于此)。 实际上我有这个: 问题是,当我点击并打开新的电子邮件时,我只在身体中获得以下内容: HTTP://本地主机:9001 /视图/ shopindex /显示关键字=测试 我认为mailto正在识别网页URL的查询字符串中的&符号,作为mailto URL的一部分。 有没有办法逃脱它? 谢谢! Krt_Malta

具有当前弹性搜索版本的Spring Boot应用程序

我最近尝试将elasticsearch包含在我的一个项目中。 因此,我查了不同的可能性。 它基本上归结为使用a)传输客户端(内部协议集群节点也用于通信=我的理解)或b)将其全部实现为我自己的REST HTTP调用。 因为b)看起来不是一个好的选择,而且我习惯于弹出数据,我尝试使用spring-data-elasticsearch,最近更新到版本3.0.0以支持es 5.5.0,这是最后一个很好的版本很老了。 好吧,我尝试了所有的东西,但没有设法让它与我的项目一起工作,因为这似乎是某种依赖性你会陷入其中。 我的项目太大了,我只是无法升级到spring boot 2.0.0M4,我认为这需要支持新的spring-data-elasticsearch版本 – 对吧? 那么,有人可以就当前和首选的方式提出建议吗?未来是关于如何在春季项目中处理弹性搜索? 我们真的必须自己实现整个REST API吗? 我错过了什么吗? 这是应该使用的REST客户端,如果有一个使用,对吧? 这是我知道的旧兼容性图表。 谢谢!