我想将以下(工作)curl片段转换为RestTemplate调用:
curl -i -X POST -d "email=first.last@example.com" https://app.example.com/hr/email
Run Code Online (Sandbox Code Playgroud)
如何正确传递电子邮件参数?以下代码导致404 Not Found响应:
String url = "https://app.example.com/hr/email";
Map<String, String> params = new HashMap<String, String>();
params.put("email", "first.last@example.com");
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity( url, params, String.class );
Run Code Online (Sandbox Code Playgroud)
我试图在PostMan中制定正确的调用,我可以通过将body参数指定为正文中的"form-data"参数来使其正常工作.在RestTemplate中实现此功能的正确方法是什么?
任何人都可以使用Spring rest模板为我提供代码示例来访问使用https保护的休息服务URL.
我有证书,用户名和密码.基本身份验证在服务器端使用,我想创建一个客户端,可以使用提供的证书,用户名和密码(如果需要)连接到该服务器.
是否可以在不使用任何Git仓库的情况下使用Spring Cloud Config?我正在尝试使用application.properties中的本地目录来测试它:
spring.cloud.config.server.git.uri=file://${user.dir}/src/main/resources/config-repo
但是我收到以下错误:
java.lang.IllegalStateException:文件中没有.git:// path/to/src/main/resources/config-repo
如果一个人根本不使用Git,那么就不可能使用Spring Cloud吗?
更新:
感谢Spencer的建议,我补充了以下内容:
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=${user.dir}/src/main/resources/configs
我在"configs"中有一个文件"bar.properties",其中包含以下内容:
foo: bar
Run Code Online (Sandbox Code Playgroud)
但我得到的反应不是读取文件:
{
"name": "bar",
"profiles": [
"default"
],
"label": "master",
"propertySources": []
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的URL是http:// localhost:8888/bar/default
我错过了别的什么吗?再次感谢您!
我正在尝试找到更快的批量插入方法.
我试图用jdbcTemplate.update(String sql)插入几个批处理,其中sql是由StringBuilder 构建的,如下所示:
INSERT INTO TABLE(x, y, i) VALUES(1,2,3), (1,2,3), ... , (1,2,3)
Run Code Online (Sandbox Code Playgroud)
批量大小正好是1000.我插入了近100批.我使用StopWatch检查了时间并找出了插入时间:
min[38ms], avg[50ms], max[190ms] per batch
Run Code Online (Sandbox Code Playgroud)
我很高兴,但我想让我的代码变得更好.
之后,我尝试使用jdbcTemplate.batchUpdate,如:
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
// ...
}
@Override
public int getBatchSize() {
return 1000;
}
});
Run Code Online (Sandbox Code Playgroud)
sql的样子
INSERT INTO TABLE(x, y, i) VALUES(1,2,3);
Run Code Online (Sandbox Code Playgroud)
我很失望!jdbcTemplate以分开的方式执行1000行批处理的每个插入.我在mysql_log上找到了,发现有一千个插入.我使用StopWatch检查了时间并找出了插入时间:
min [900ms],avg [1100ms],每批最大[2000ms]
那么,任何人都可以向我解释一下,为什么jdbcTemplate在这个方法中做了单独的插入?为什么方法的名称是batchUpdate?或者可能是我以错误的方式使用这种方法?
我正在使用Tomcat7,Spring框架进行ReST Web服务.我试图使用Spring RestTemplate调用https Web服务.我收到以下错误:
无法找到要求目标的有效证书路径; 嵌套异常是javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径
我在stackoverflow上在线检查.我尝试了url中的示例代码: 使用Spring RestTemplate访问Https Rest服务
我无法让它发挥作用.任何人都可以根据下面的代码告诉我,我需要更改什么?也有人可以告诉我或者向我提供我需要的java库的pom.xml文件吗?
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.journaldev.spring.controller.EmpRestURIConstants;
import com.journaldev.spring.model.CostControlPost;
import com.journaldev.spring.model.Employee;
import com.journaldev.spring.model.RfxForUpdate;
import static org.junit.Assert.*;
import org.apache.commons.codec.binary.Base64;
import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class TestExample2
{
public static final String SERVER_LIST="https://abc/sourcing/testServices";
@Test
public void testGetListOfServiceNames()
{
try
{
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(SERVER_LIST,HttpMethod.GET,null,String.class);
assertNotNull(response);
}
catch(Exception e)
{
System.out.println("e:"+e.getMessage()); …Run Code Online (Sandbox Code Playgroud) 我已经使用Firebug通过JavaScript调试了一百多次而不用担心那里发生了什么.我想知道Firebug究竟是如何处理JavaScript/DOM调试的.
假设我在方法内的某个语句上设置了一个断点并开始调试.我想知道那里发生了什么?
我想配置我的春天@MVC存根应用程序的春天RestTemplate与SSL进行沟通,REST基地HTTPS应用程序中,部署在Tomcat的服务器(春季3,Tomcat的7).我已经完成了我的作品,请参阅此链接.现在我没有任何想法如何使用这些生成的证书与春天RestTemplate,任何人都可以有一些想法,请帮助我.谢谢.到目前为止我做过的事情,
// Spring Security xml配置
<http>
<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https"/>
<http-basic/></http>
Run Code Online (Sandbox Code Playgroud)
//使用Tomcat启用SSL的配置
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="C:\Users\Channa\.keystore" keystorePass="changeit"
clientAuth="false" sslProtocol="TLS"/>
Run Code Online (Sandbox Code Playgroud)
用于生成密钥,证书等,
//生成客户端和服务器密钥:
F:\ jdk1.6.0_23\bin> keytool -genkey -keystore keystore_client -alias clientKey -dname"CN = localhost,OU = Dev,O = MyBusiness,L = Colombo,S = Westen,C = SL"
F:\ jdk1 .6.0_23\bin> keytool -genkey -keystore keystore_server -alias serverKey -dname"CN = localhost,OU = Dev,O = MyBusiness,L …
我可能在这里遗漏了一些东西,但是什么是属性版本控制的好方法?
例如,在具有属性值更改的蓝绿色部署方案中(旧应用程序版本消耗旧值,新版本需要新值),如何确保应用程序的两个版本可以成功共存(考虑可能的重新启动和回滚)?
一种选择是为需要应用新值的属性创建新的属性名称.当然,这不是一个好的选择,因为我们需要在代码库中跟踪该属性的所有用法并相应地更新其引用.从概念的角度来看,它也不是很好.
另一种选择是为每个版本分配一个分支.虽然这对于这种情况可以很好地工作,但我设想一个分支/标记地狱,因为我们扩展到配置仓库到多个应用程序,它们各自的分支演变成不同的方向.
分支机构的解决方案是为每个应用程序分配一个配置存储库.但是,我认为这在某种意义上会破坏配置服务器的目的,因为它增加了开销.
还有其他方法吗?
我有200K行要插入一个数据库表中.我尝试jdbcTemplate.batchUpdate在春天使用,以便每批次插入10,000.但是,此过程会消耗太多时间(对于200K行,为7分钟).所以在数据库方面,我检查插入的行数select count(*) from table_X.我发现行数略有增加,预计为10K.任何人都可以解释是什么原因或者是应该在数据库端配置的东西吗?
PS:我正在使用sybase ....
spring ×7
java ×5
resttemplate ×4
rest ×3
jdbctemplate ×2
spring-cloud ×2
certificate ×1
debugging ×1
firebug ×1
firefox ×1
https ×1
internals ×1
mysql ×1
spring-batch ×1
spring-boot ×1
sql ×1
sybase ×1
syntax ×1
versioning ×1
xml ×1
yaml ×1