我有一个列表如下:
ArrayList<DiameterMessageHandler> handlers = new ArrayList<>();
handlers.add(new AARHandler());
handlers.add(new CERHandler());
handlers.add(new PPAHandler());
handlers.add(new STRHandler());
handlers.add(new DWRHandler());
Run Code Online (Sandbox Code Playgroud)
我想知道如何创建一个将处理程序作为其参数之一的spring bean,即是否可以在applicationContext.xml中执行此操作 - 我是否必须为列表和每个处理程序(AARHandler等)创建单独的bean第一?这是我的applicationContext.xml
<bean id="DiameterClient" class="com.rory.ptspsim.diameterclient.DiameterClient" scope="singleton" init-method="start">
<constructor-arg type="java.lang.String" index="0"><value>${pcca.host}</value></constructor-arg>
<constructor-arg index="1">WHAT GOES HERE?</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在最新的netbeans的全新安装上构建一个现有的maven项目但是我收到以下错误,非常感谢任何帮助:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.rory.ngp.test: Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7
Run Code Online (Sandbox Code Playgroud)
我认为它与路径有关,但我不确定.这是我的内容/usr/lib/jvm directory;
bash-4.1$ pwd
/usr/lib/jvm
bash-4.1$ ls
java java-openjdk jre-1.6.0-openjdk.x86_64
java-1.5.0-gcj-1.5.0.0 jre jre-gcj
java-1.6.0 jre-1.5.0 jre-openjdk
java-1.6.0-openjdk-1.6.0.0.x86_64 jre-1.5.0-gcj
java-1.6.0-openjdk.x86_64 jre-1.6.0
Run Code Online (Sandbox Code Playgroud) 我遇到了我的Spring控制器问题 - 我没有找到默认的构造函数 - 但是他们确实有一个我试图通过applicationContext.xml创建的构造函数 - 以下是相关的一点:
<bean id="PcrfSimulator" class="com.rory.services.pcrf.simulator.PcrfSimulator" init-method="start">
</bean>
<bean id="CacheHandler" class="com.rory.services.pcrf.simulator.handlers.CacheHandler">
<constructor-arg index="0" type="com.rory.services.pcrf.simulator.CustomGxSessionIdCacheImpl">
<bean factory-bean="PcrfSimulator" factory-method="getGxSessionIdCache">
</bean>
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
IE浏览器.我首先创建一个bean,然后尝试将该bean的方法调用结果传递给第二个bean的(CacheHandler)构造函数.
这是CacheHandler的开始:
@Controller
public class CacheHandler {
private final CustomGxSessionIdCacheImpl gxSessionIdCache;
public CacheHandler(CustomGxSessionIdCacheImpl gxSessionIdCache) {
this.gxSessionIdCache = gxSessionIdCache;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheHandler' defined in URL [jar:file:/users/rtorney/Documents/apache-tomcat-7.0.25/webapps/PCRFSimulator-4.0/WEB-INF/lib/PCRFSimulator-4.0.jar!/com/rory/services/pcrf/simulator/handlers/CacheHandler.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rory.services.pcrf.simulator.handlers.CacheHandler]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.rory.services.pcrf.simulator.handlers.CacheHandler.<init>()
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!
我只是想知道是否有可能使用Junit和easymock来忽略意外的方法调用?
即不是测试失败,我想能够说 - "此时 - 忽略任何意外的方法调用,并继续正常的测试'
谢谢
我正在使用Apache Commons CLI.默认情况下,它按键按字母顺序命令命令行上的选项.那么,看来是:
-csv
-ip
-msisdn
-xml
Run Code Online (Sandbox Code Playgroud)
但我想按如下顺序排序:
-csv
-xml
-ip
-msisdn
Run Code Online (Sandbox Code Playgroud)
我知道你可以使用一个OptionFormatter类并传递给HelpFormatter,但是看不到任何关于如何将它用于上述目的的例子(http://www.marko.homeunix.org/programming/java/公地-CLI/API /组织/阿帕奇/公地/ CLI/HelpFormatter.OptionComparator.html).
只是想知道有没有人做过类似的事情?
谢谢
在我的HTML页面上,我向一个强制下载的php脚本发出了一个JQuery ajax请求,但什么也没发生?
在我的html页面上(在链接的点击事件处理程序中)......
var file = "uploads/test.css";
$.ajax(
{
type : "POST",
url : "utils/Download_File.php",
data : {"file":file}
})
Run Code Online (Sandbox Code Playgroud)
Download_File.php脚本如下所示
<?php
Download_File::download();
class Download_File
{
public static function download()
{
$file = $_POST['file'];
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment');
readfile('http://localhost/myapp/' . $file);
exit;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
但是由于某种原因什么都没发生?我查看了firebug中的响应头,无法看到任何问题.我正在使用Xampp.任何帮助深表感谢.
谢谢!
我有一个MySQL数据库,其中包含一个包含datetime列的表.
但是,我无法在Java中找到一种方法将其作为TimeJava中的某种对象返回.
我可以打电话resultset.getString("Date"),它会返回datetime,但这并不好,因为没有办法比较字符串上的日期等.
我也可以打电话resultset.getDate("Date"),但这根本不会让时间恢复.
我在最新版本的Netbeans中有一个maven项目但是由于我的环境/ maven设置存在未确定的问题,我必须使用gmake从命令行构建项目,因为使用mvn clean install构建会出现很多错误.
所以,我想知道我是从命令行构建的,当使用netbeans来运行项目/主类时,如何在没有它首先构建/编译的情况下运行它 - 即每次我右键单击主类并选择运行文件 - 它会说 - '构建......' - 我可以在没有构建/编译的情况下运行该文件吗?
谢谢!
在Spring MVC中,我可以这样做以获取查询字符串上的项值:
public void sendMessage(HttpServletResponse response,
@RequestParam("Session Id") String sessionId,
Run Code Online (Sandbox Code Playgroud)
但是如何将完整的查询字符串作为一个长字符串?即我不想要它的个别参数,我想要整个事情?
非常感谢!
我有一个单独的Spring bean(默认范围).因此,多个线程将使用一个实例.但是,我对线程安全有点困惑,显然所有Spring bean都是线程安全的,如果它们是无状态的,但我的bean不是无状态的,它有各种实例变量,每个请求/其他控制器/类使用它们.
这是我的单例bean的开头:
public class PcrfSimulator {
private final CustomGxSessionIdCacheImpl gxSessionIdCache = new CustomGxSessionIdCacheImpl();
private final PcrfRecord pcrfRec = new PcrfRecord();
private final ResponseConditions responseConditions = new ResponseConditions();
public CustomGxSessionIdCacheImpl getGxSessionIdCache() {
return gxSessionIdCache;
}
public ArrayList<Rule> getRules() {
return pcrfRec.getRules();
}
Run Code Online (Sandbox Code Playgroud)
因此,上面的字段将由多个线程访问 - 是否足以将这些字段标记为易失性,或者我是否必须标记访问它们的方法(不仅有这个类,而且其他控制器/类有很多)以及同步和使用等待/通知等?
非常感谢!