我正在使用Spring框架为基于Web的应用程序设计插件系统.插件是类路径上的jar.所以我能够得到像jsp这样的资源,见下文
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] pages = resolver.getResources("classpath*:jsp/*jsp");
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.但我的messageSource有问题.在我看来,ReloadableResourceBundleMessageSource #setBasename不支持通过"classpath*:"的多个类路径.如果我只使用"classpath:",我只从一个插件获取messageSource.
有没有人知道如何从所有插件注册messageSources?是否存在MessageSource的这种实现?
保罗格雷厄姆在他的伟大文章"复仇的书呆子"中声称,语言的力量各不相同.他提到了一个很好的练习 - 写一个累加器发生器:
我们想要编写一个生成累加器的函数 - 一个取n的函数,并返回一个函数,它取另一个数字i并返回n递增i.
Java中的解决方案是
public class Accumulator {
public interface Inttoint {
public int call(int i);
}
public static Inttoint foo(final int n) {
return new Inttoint() {
int s = n;
public int call(int i) {
s = s + i;
return s;
}};
}
public static void main(String... args) {
Inttoint accumulator = foo(1);
System.out.println(accumulator.call(2) == 3);
System.out.println(accumulator.call(3) == 6);
}
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,无论是在Java 8(感谢lambda)已经是一些优雅的方式如何写它类似于Groovy,见下文.我试过了Function<Integer, Integer>
但我坚持这个编译器错误.
从lambda表达式引用的局部变量必须是最终的或有效的final
那么你有一些Java 8解决方案吗?
将旧的Java解决方案与Groovy解决方案进行比较 …
我在 JBOSS 的 run.conf 中添加了一个系统属性,如下所示:
JAVA_OPTS="$JAVA_OPTS -Dfoo=bar"
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,是否有办法以如下方式解析 web.xml 文件中的此属性:
...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-common.xml
classpath:conf/${foo}/applicationContext-local.xml
</param-value>
</context-param>
...
Run Code Online (Sandbox Code Playgroud) 我使用SOAPMessage.writeTo(OutputStream)来记录Web服务消息.问题是它还会写附件.它占用空间,二进制附件不可读.有没有办法如何记录没有附件的邮件,例如包装器?
必须有比这更好的解决方案.
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
StringBuilder builder = new StringBuilder(out.toString());
int indexOfAttachment = builder.indexOf("------=");
if (indexOfAttachment != -1) {
return builder.substring(0, indexOfAttachment);
}
return builder.toString();
Run Code Online (Sandbox Code Playgroud)
示例消息
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header />
<S:Body>
<ns2:wsGetObjectByIDResponse
xmlns:ns2="http://xxx.com/"
xmlns:ns3="http://yyy.com/">
<return>
<serviceResponse status="OK" />
<contentData formatName="jpeg_lres"
objectContent="cid:e677f02c-002a-4c2c-8fd9-a3acdba5ad11@example.jaxws.sun.com"
objectName="Smlouva1.jpg" />
</return>
</ns2:wsGetObjectByIDResponse>
</S:Body>
</S:Envelope>
------=_Part_9_-806948376.1352979403086
Content-Type: image/jpeg
Content-ID: <e677f02c-002a-4c2c-8fd9-a3acdba5ad11@example.jaxws.sun.com>
Content-Transfer-Encoding: binary
????\x00JFIF\x00\x00?\x00?\x00\x00??\x00C\x00
Run Code Online (Sandbox Code Playgroud) 注意:类似的问题已经在三年前提出过,在EE 6的时候,看看如何为一个类实例化多个CDI/Weld bean?EE 7有什么变化吗?
在Spring中,可以通过在xml conf中定义相应的bean来实例化任何类.也可以为一个具有不同参数的类实例化更多的bean .....
是否可以在CDI中执行此操作,我的意思是创建一个实例而不创建另一个类?
春天的例子:
<bean id="foo" class="MyBean">
<property name="someProperty" value="42"/>
</bean>
<bean id="hoo" class="MyBean">
<property name="someProperty" value="666"/>
</bean>
Run Code Online (Sandbox Code Playgroud) 我在64位linux(Ubuntu 10.04)上安装java j2sdk 1.4.2时遇到问题.有人处理过吗?
uname -a
2.6.32-25-generic#44-Ubuntu SMP Fri Sep 17 20:05:27 UTC 2010 x86_64 GNU/Linux
我运行一个自解压文件
sudo ./j2sdk-1_4_2_02-linux-i586.bin
但我明白了
tail:无法打开`+473'进行阅读:没有这样的文件或目录
Oracle论坛没有答案.