我想在我的Spring Boot项目中使用Zuul.
application.properties
server.context-path=/${spring.application.name}
zuul.routes.engine.path=/api/engine/**
zuul.routes.engine.url=${engine.url}
Run Code Online (Sandbox Code Playgroud)
GET请求正在运行; 但是,Zuul没有转发我的POST请求.我没有看到任何调试输出为无论是GET还是POST在这里列出:如何使用.
如何DEBUG为Zuul 启用日志记录模式?
在JUnit 4测试中,我有一个方法getValues()返回一个List<Double>我想要与引用列表进行比较的对象.到目前为止,我发现的最佳解决方案是使用org.hamcrest.collection.IsArray.hasItems和org.hamcrest.Matchers.closeTo喜欢这样:
assertThat(getValues(), hasItems(closeTo(0.2, EPSILON), closeTo(0.3, EPSILON)));
Run Code Online (Sandbox Code Playgroud)
这适用于仅返回少量值的测试.但是如果测试返回更多值,这绝对不是最好的方法.
我也尝试了以下代码.要编译的代码需要向下转换为Matcherbefore hasItems:
List<Matcher<Double>> doubleMatcherList = new ArrayList<Matcher<Double>>();
doubleMatcherList.add(closeTo(0.2, EPSILON));
doubleMatcherList.add(closeTo(0.3, EPSILON));
assertThat(getValues(), (Matcher) hasItems(doubleMatcherList));
Run Code Online (Sandbox Code Playgroud)
比较失败,我不明白为什么:
java.lang.AssertionError:Expected :(一个包含<[数字值<1.0E-6> <0.2>的数字,<1.0> -0> <0.3>的数值>]>的集合得到:<[ 0.2,0.30000000000000004]>
是否有更好的方法来比较两个大型双打名单?这里的困难是需要数值公差来验证结果getValues()是否等于我的参考列表.对于任何对象列表,这种比较似乎都很容易,但对于列表却没有Double.
我已经尝试通过curl执行此命令从我的oauth2服务器请求代码
curl -X POST -k -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "grant_type=authorization_code&scope=read%20write&client_secret=123456&client_id=clientapp&code=appcode&redirect_uri=localhost:3000"
Run Code Online (Sandbox Code Playgroud)
回应是
* Adding handle: conn: 0x608860
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x608860) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'clientapp'
> POST /oauth/token HTTP/1.1
> Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==
> User-Agent: …Run Code Online (Sandbox Code Playgroud) 我可以public static final在界面中创建变量吗?我可以保留这些文件中定义的常用常量值吗?
由于c3p0连接池的问题,我想看看替代方案,并决定哪一个可能更适用于我的情况.HikariCP看起来非常有前景,但没有文档说明如何将它与Hibernate一起使用.
到目前为止,我使用c3p0如下:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${database.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${database.structure}</prop>
<prop key="hibernate.connection.url">${database.connection}</prop>
<prop key="hibernate.connection.username">${database.username}</prop>
<prop key="hibernate.connection.password">${database.password}</prop>
<prop key="hibernate.connection.driver_class">${database.driver}</prop>
<prop key="hibernate.connection.shutdown">true</prop>
<prop key="hibernate.connection.writedelay">0</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.show_sql">${database.show_sql}</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.ejb.metamodel.generation">disabled</prop>
<!-- Use the C3P0 connection pool provider -->
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">30</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.idle_test_period">600</prop>
</props>
</property>
Run Code Online (Sandbox Code Playgroud)
有人能指出我如何以这种方式配置HikariCP吗?
我即将实现REST api.我想知道HttpStatus.OK和之间有什么区别HttpStatus.ACCEPTED:
return new ResponseEntity<User>(u, HttpStatus.OK));
Run Code Online (Sandbox Code Playgroud)
和
return new ResponseEntity<User>(u, HttpStatus.ACCEPTED);
Run Code Online (Sandbox Code Playgroud) 我在Spring 4.1.4应用程序中使用了最新的Ehcache.我有的是:
class Contact{
int id;
int revision;
}
@Cacheable("contacts")
public List<Contact> getContactList(List<Integer> contactIdList) {
return namedJdbc.queryForList("select * from contact where id in (:idlist)", Collections.singletonMap("idlist", contactIdList));
}
@CachePut(value="contact", key = "id")
public void updateContact(Contact toUpdate) {
jdbctemplate.update("update contact set revision = ? where id = ?", contact.getRevision(), contact.getId());
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,联系人存储在缓存中,当我getContactList再次调用该方法时,id从缓存中检索已缓存的所有联系人,并且应该正常查询其他联系人然后缓存.然后,此缓存应在更新时更新缓存的联系人实体.
我使用普通的Spring JDBC和Ehcache,没有JPA,也没有Hibernate.
我刚刚完成了 Micheal Hartl 的 Ruby on Rails 教程的第 3 章。在本章的最后部分,他要求将 gitignore 文件配置为不与“由 Rails 提供以加快加载时间”的 spring 服务器冲突。我对编程完全陌生,想更清楚地了解这个 Spring 服务器是什么。我试过谷歌搜索,但没有外行的答案。谢谢!
我有一个关于Spring的@Async注释以及如何正确使用它的问题.假设我有这些方法:
@Async
public void test(String param1) {
test2(param1, null);
}
@Async
public void test2(String param1, String param2) {
test3(param1, param2, null);
}
@Async
public void test3(String param1, String param2, String param3) {
// do some heavy work
}
Run Code Online (Sandbox Code Playgroud)
我是否需要@Async在所有三种方法上进行异步调用,或者只是将其置于test3实际上才能完成工作?
我有一个方法:
@Cacheable(key = "#jobId")
public Optional<JobInfo> getJobById(String jobId) {
log.info("Querying for job " + jobId);
counterService.increment("queryJobById");
Job job = jobsRepository.findOne(jobId);
if (job != null) {
return Optional.of(createDTOFromJob(job));
}
return Optional.empty();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试检索缓存的项目时,我收到以下异常:
2016-01-18 00:01:10 ERROR [trace =,span =] http-nio-8021-exec-2 [dispatcherServlet]:182 - Servlet [dispatcherServlet]的Servlet.service()在路径[]的上下文中抛出异常[请求处理失败; 嵌套异常是org.springframework.data.redis.serializer.SerializationException:无法序列化; 嵌套异常是org.springframework.core.serializer.support.SerializationFailedException:无法使用DefaultSerializer序列化对象; 嵌套异常是java.lang.IllegalArgumentException:DefaultSerializer需要一个Serializable有效负载,但是收到一个类型为[java.util.Optional]的对象,其根本原因是java.lang.IllegalArgumentException:DefaultSerializer需要一个Serializable有效负载但是收到了一个类型为[java的对象] .util.Optional]
spring ×6
java ×5
spring-boot ×2
api ×1
asynchronous ×1
c3p0 ×1
constants ×1
ehcache ×1
guard ×1
hamcrest ×1
hibernate ×1
hikaricp ×1
interface ×1
jdbctemplate ×1
junit ×1
netflix-zuul ×1
oauth2 ×1
rest ×1
ruby ×1
spring-cache ×1
spring-cloud ×1
spring-mvc ×1