我的代码看起来像这样:
for (Map.Entry<Integer, Action> entry : availableActions.entrySet()) {
...
}
Run Code Online (Sandbox Code Playgroud)
我试图像这样嘲笑它:
Map mockAvailableActions = mock(Map.class, Mockito.RETURNS_DEEP_STUBS);
mockAvailableActions.put(new Integer(1), mockAction);
Run Code Online (Sandbox Code Playgroud)
我认为这就足够了.但是entrySet是空的.所以我补充说:
when(mockAvailableActions.entrySet().iterator()).thenReturn(mockIterator);
when(mockIterator.next()).thenReturn(mockAction);
Run Code Online (Sandbox Code Playgroud)
仍然是entrySet为空.我究竟做错了什么?感谢您的任何意见!
因此,我想在Appengine中使用Guice和Cloud Endpoints来注入我的服务或者daos - 我猜这很常见,但我没有找到这方面的教程.
官方Guice for Appengine文档似乎在这里:https://github.com/google/guice/wiki/GoogleAppEngine
配置Guice时,您需要设置com.google.inject.servlet.GuiceFilter来拦截每个请求"/*".在某些时候,您必须初始化模块.就像文档说的那样,一个好的地方就是ServletContextListener.
一种特殊的模块是ServletModules,它将请求路径映射到Servlet-Classes,而不是在web.xml中执行此操作,您现在可以通过编程方式执行此操作.
非常直接,直到这里.但是如何配置Guice还包括Endpoint-Class?
google-app-engine dependency-injection guice google-cloud-endpoints
我正在使用Drowpizard 0.7.1,但也许我很快会升级到0.8.4.
有没有人知道如何向dropwizard添加管理资源,这在操作菜单中显示,如下例所示?
Operational Menu
Metrics
Ping
Threads
Healthcheck
CustomAdminXy
Run Code Online (Sandbox Code Playgroud) 这是Java代码的片段:
int[][] uu = new int[1][1];
uu[0][0] = 5;
for(int[] u: uu){
System.out.println(u[0]);
}
Run Code Online (Sandbox Code Playgroud)
它打印5.但为什么声明for循环的声明部分as int[] u,但不是as int[][] u?
在uu你引用2D数组...这不是一个功课.我正在准备Java认证.干杯
我正在尝试使用编写应用程序Spring 3.1.2-Release.应用服务器是Tomcat 7.当我启动服务器时,我收到此错误:
SEVERE:异常启动过滤器springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException:否
名为'springSecurityFilterChain'的bean在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553)的org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)中定义. Org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)位于org.springframework.context.support的org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197). AbstractApplicationContext.getBean(AbstractApplicationContext.java:1102)
这是我的配置文件:
web.xml
Run Code Online (Sandbox Code Playgroud)
<display-name>myTest</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>springTest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springTest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
这是 root-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd …Run Code Online (Sandbox Code Playgroud) 有谁知道如何从Flyway记录sql输出?它只记录sql错误但我需要记录诸如"table created","table dropped"等信息...
谢谢.
我正在掌握Spark框架,并且我正在尝试理解以多种路径的统一方式处理异常的最佳方法.
目前我有许多路由,它们都按以下方式处理异常:
...
catch (final Exception e) {
...
response.status(418);
return e.getMessage();
}
...
Run Code Online (Sandbox Code Playgroud)
这留下了很多不足之处,主要是异常逻辑在它们之间重复.我知道它可以通过重构来改进,但我想知道是否有类似于Spring中的ExceptionHandler机制,您可以在抛出特定异常时执行操作,例如:
@ExceptionHandler(Exception.class)
public void handleException(final Exception e, final HttpServletRequest request) {
...executed for the matching exception...
}
Run Code Online (Sandbox Code Playgroud)
那么,是否存在用于异常处理的Spark-esque机制?我查了一下文档并做了简短的介绍.如果没有,我将继续我的重构计划.谢谢.
我正在使用file_get_contents('php://input')从特定Web服务检索所有POST参数/值,例如:
$postText = file_get_contents('php://input');
Run Code Online (Sandbox Code Playgroud)
结果是这样的:
inReplyToId=MG1133&to=61477751386&body=test&from=61477751386&messageId=166594397&rateCode=
Run Code Online (Sandbox Code Playgroud)
然后我需要获取每个单独的键/值对,因为我需要将它们设置到新数据库记录中的字段中.例如,我想最终得到:
$inReplyToId = MG1133
$to = 61477751386
$body = test
Run Code Online (Sandbox Code Playgroud)
一旦我知道了单个值,我就可以在数据库中设置相应的字段.我通常会使用:
if(isset($_POST['inReplyToId']) && $_POST['inReplyToId'] !== '' ) {
$request->setField('_kf_GatewayMessageID', $_POST['inReplyToId']);
}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,这不起作用,因为它不是一个application/x-www-form-urlencoded提交的表格.
如何在Spring MVC中配置Netty.我应该何时何地启动Netty tcp服务器?一旦Spring开始,我应该初始化netty吗?有人能告诉我一个例子,例如Spring配置xml文件或eles吗?谢谢!
我正在尝试扩展eclipse的重命名重构以调用另一个重命名重构.
public class Person {
...
}
public class PersonDAO {
public List<Person> getPersonByName(String name) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
将Person类重命名为User后,我希望将方法getPersonByName重命名为getUserByName.
我已经扩展了RenameParticipant并试图通过使用JDT重命名重构和ASTRewrite来实现.
问题是我创建的更改与原始重命名重构更改冲突.
我无法使用postCreateChange(似乎基本处理器只返回null)现在我卡住了.
任何帮助深表感谢.
java ×7
arrays ×2
admin ×1
dropwizard ×1
eclipse ×1
flyway ×1
foreach ×1
guice ×1
ltk ×1
mockito ×1
netty ×1
php ×1
refactoring ×1
rename ×1
servlets ×1
spark-java ×1
spring ×1
spring-mvc ×1
web.xml ×1