我有一个方法:
void putObject(<T extends BaseEntity> param)
Run Code Online (Sandbox Code Playgroud)
有一些测试,我嘲笑这个方法,但我想知道,如何验证该方法是否被特定类的参数调用?试图以这样的方式做到:
verify(foo).putObject((SomeClass)anyObject());
------
verify(foo).putObject(any(SomeClass.class));
------
ArgumentCaptor<SomeClass> parameter = ArgumentCaptor
.forClass(SomeClass.class);
verify(foo).putObject(parametr);
Run Code Online (Sandbox Code Playgroud)
仅使用第二个变体any()
,但它不t check class of
参数` .那么,如果有可能验证该方法获得特定类的任何对象?
我有一个复杂的Maven项目,它有一个父文件夹,父pom.xml
文件夹和子项目的子文件夹,每个子文件夹都有自己的子项目pom.xml
.
当我从SVN存储库'作为maven项目'签出父文件夹时,它在工作区中正确显示为每个单独的项目.
但是现在我从项目的其他分支中检出了父文件夹.我想以相同的方式将此父文件夹添加到当前工作空间.所以我只是选择Import > Maven project
,从svn得到与checkout相同的对话框,Eclipse找到所有具有适当层次结构的pom文件并要求我给父项目提供其他名称,因为alredy存在相同的名称(截面版本的项目),我给它其他名称.但是在导入之后我在eclipse中只将父文件夹作为maven项目,所有其他子项目都很简单,位于父项目下作为其子文件夹.
那么,我怎样才能导入这样的项目呢?我只想将所有子项目创建为maven项目.
我已经阅读了很多关于在生产服务器上部署Symfony 2项目的文章和问题,但是,目前还不清楚.Symfony项目的部署看起来很糟糕 - 没人知道如何正确地做到这一点.我想我看到的最好的主题是部署一个Symfony2项目,但是,很多事情并不清楚.我读了它,发现在那个问题中,有人将自己的IP添加到允许的IP列表中,但这意味着只有这个IP可以访问这个站点,但我需要允许每个人都使用它.
我怎样才能使网站与路径一起工作www.mydomen.com
,而不是www.mydomen.com/web/app_dev.php/index
(我可以通过Symfony纠正路径,但它可以在app_dev.php
托管后通过托管工作,但是它怎么能在/之前工作app_dev.php
??似乎app-dev.php应该始终在我的路径中).
那么我应该如何正确地将开发的项目从本地服务器正确地转移到生产服务器呢?
我尝试获取页面上主 div 的大小,以使 iframe 将其高度更改为内容,但document.getElementById("divId").offsetHeight
(也尝试innerHeight
)返回错误的值。它总是返回 247,但实际上页面看起来减少了 75%。我知道页面没有完全加载,所以我将调整大小代码放在页面的页脚中,但它仍然返回 247。
$(document).ready(function() {
console.log(document.getElementById("resizeDiv").offsetHeight);
});
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
我必须从 Spring Security 堆栈中排除一个默认过滤器。所以所有过滤器都应该像往常一样工作。似乎我找到了这样做的方法,制作自定义 FilterChainProxy:
public class CustomFilterChainProxy extends FilterChainProxy {
Logger LOGGER = Logger.getLogger(CustomFilterChainProxy.class);
public CustomFilterChainProxy() {
super();
LOGGER.debug("Run custom filter proxy");
LOGGER.debug("String filters: " + this.toString());
}
public CustomFilterChainProxy(SecurityFilterChain chain) {
super(chain);
LOGGER.debug("Run custom filter proxy with chains");
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它具有获取过滤器列表的构造函数,因此我将能够根据需要从链中删除一个过滤器,其余所有过滤器将照常工作。但是我不能在安全配置中为这样的构造函数创建 bean。如果我使用
<bean id="filterChainProxy" class="com.pkg.CustomFilterChainProxy">
Run Code Online (Sandbox Code Playgroud)
它,当然用默认构造函数构建对象。好的,我尝试使用一些过滤器列表制作 bean:
<bean id="filterChainProxy" class="ru.olekstra.backoffice.util.CustomFilterChainProxy">
<constructor-arg>
<list>
<sec:filter-chain pattern="/**"
filters="BasicUserApprovalFilter" />
</list>
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
但这不会编译,因为 BasicUserApprovalFilter 是未知 bean。那么如何从默认过滤器堆栈中排除一个过滤器呢?如果我使用自定义过滤器链代理的方式是好的决定,那么如何使用默认过滤器链创建 bean?
Im 辅助方法使用 ehcache,以减少对 Db 的查询。现在想实现JUnit+Mockito测试,确保ehcache正常工作。有这样的测试变体:
@Autowired
private DBService service;
@Autowired
private DiscountHelper discountHelper;
@Autowired
private CacheManager cacheManager;
@Before
public void setUp() throws Exception {
assertNotNull(cacheManager);
}
@Test
public void testGetDiscountWithCache() throws RuntimeException,
InterruptedException {
String id1 = "id1";
String id2 = "id2";
String id3 = "id3";
List<String> discountsId = new ArrayList<String>();
discountsId.add(id1);
discountsId.add(id2);
discountsId.add(id3);
List<Map<String, Object>> attrList = new ArrayList<Map<String, Object>>();
attrList.add(new Discount().getAttributes());
attrList.add(new Discount().getAttributes());
attrList.add(new Discount().getAttributes());
Cache cache = cacheManager.getCache(DiscountHelper.CACHE_NAME);
assertNotNull(cache);
assertEquals(0, cache.getSize());
// First run with empty cache …
Run Code Online (Sandbox Code Playgroud) 从log4j 1.2迁移到新的log4j2。添加到pom:
<!-- Add log4j version 2 with 1.2 API -->
<dependency>
<!-- <groupId>log4j</groupId> -->
<!-- <artifactId>log4j</artifactId> -->
<!-- <version>1.2.9</version> -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.0-beta6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta6</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并尝试通过Spring上下文将其初始化为log4j(在log4j 1.2上完美运行)。用于此配置:
<!-- Init log4j with appropriate config according to enviroment -->
<bean id="log4jConfigurer-bean" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
<property name="targetMethod" value="initLogging"/>
<property name="arguments">
<list>
<value>classpath:config/env/log4j-${env.variable}.xml</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
但是看来现在行不通了吗?我做错了什么?可能是spring config应该修改吗?对spring使用这样的依赖:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我无法将数组从symfony 2控制器传递到TWIG模板.我在控制器中使用此代码:
$searchTerms['color'] = "Red";
return $this->render('TestBundle::search.html.twig',
array(
"searchTerms" => $searchTerms));
Run Code Online (Sandbox Code Playgroud)
在twig模板中,我试图像这样访问变量:
两者都没有输出,空字符串,所以看起来数组来到模板但它的元素是空的.
怎么了?
我有一个简单的非阻塞服务器与主循环:
try {
while (selector.select() > -1) {
// Wait for an event one of the registered channels
// Iterate over the set of keys for which events are available
Iterator selectedKeys = selector.selectedKeys().iterator();
while (selectedKeys.hasNext()) {
SelectionKey key = (SelectionKey) selectedKeys.next();
selectedKeys.remove();
try {
if (!key.isValid()) {
continue;
}
if (key.isConnectable()) {
connect(key);
}
// Check what event is available and deal with it
if (key.isAcceptable()) {
accept(key);
}
if (key.isReadable()) {
read(key);
}
if (key.isWritable()) {
write(key);
} …
Run Code Online (Sandbox Code Playgroud) 我想使用openshift来托管我的grails应用程序,并在Openshift上设置MySQL数据库.Openshift只提供数据库的登录名和密码,但是连接字符串是环境变量OPENSHIFT_MYSQL_DB_HOST:OPENSHIFT_MYSQL_DB_PORT的形式,我没有看到我的数据库的这个变量的实际值是什么.现在我需要设置我的YML配置来访问数据库,但我需要以某种方式从YML访问环境变量OPENSHIFT_MYSQL*.我该怎么做?
我目前正在使用Telegram机器人,似乎有些电报机器人可以在一个端点服务,因为机器人的消息中缺少将一个机器人的消息与另一个机器人的消息分开的信息.新的机器人可以在运行时出现,因此我不能为每个机器人硬编码一些单独的端点.那么有可能在运行时的spring boot中通过模板创建一个新的端点吗?
java ×4
spring ×3
mockito ×2
symfony ×2
eclipse ×1
ehcache ×1
grails ×1
javascript ×1
log4j2 ×1
maven ×1
maven-2 ×1
nio ×1
openshift ×1
php ×1
rest ×1
spring-boot ×1
telegram-bot ×1
twig ×1
unit-testing ×1
yaml ×1