小编Cro*_*wie的帖子

Swing与SWT

我应该使用什么标准来选择SWT和Swing?我认为它们都提供了令人满意的GUI性能和平台可用性.

我个人的标准目前包括:

  • 布局/布局经理;
  • 数据绑定;
  • 预建控件;
  • 易于开发.

java swing swt

4
推荐指数
1
解决办法
2134
查看次数

使用web.xml中的org.springframework.web.util.Log4jConfigListener条目进行初始化?

嗨,大家好.在使用Spring的大多数Java项目中,我在web.xml中找到此条目,该条目在服务器启动时执行:

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

目的是Log4jConfigListener什么?

在我的遗留项目中,我也可以看到此设置.但是当我深入研究代码时,我没有在这个类或本类内部调用的其他类中找到任何特殊的东西.我相信在上面的代码片段背后肯定有一些好的目的,我错过了它.

在每个将日志放入文件的类中都是条目

private static final Log    log  = LogFactory.getLog(PoolManagerImpl.class);
log.debug("Number of connection pools to create = ["
    + connection.size() + "]");
Run Code Online (Sandbox Code Playgroud)

即使我注释掉我的web.xml条目,日志记录工作正常.那它的目的是什么?

java spring log4j

3
推荐指数
1
解决办法
1万
查看次数

Hazelcast的分布式锁定无法正常工作

我试图测试我的分布式锁实现,但我还没有找到一种方法使其工作.我用两个简单的方法部署了一个REST服务,如下所示:

@GET
@Path("/lock")
@Produces("text/*")
public String lock() throws InterruptedException {
    Lock lock = distributedService.getDistributedLock("test");
    boolean result = lock.tryLock(5, TimeUnit.SECONDS);
    return result ? "locked" : "timeout";
}

@GET
@Path("/unlock")
@Produces("text/*")
public String unlock() {
    Lock lock = distributedService.getDistributedLock("test");
    lock.unlock();
    return "unlocked";
}
Run Code Online (Sandbox Code Playgroud)

所述distributedService对象实现getDistributedLock()方法:

@Override
public Lock getDistributedLock(String lockName) {
    return Hazelcast.getDefaultInstance().getLock(lockName);
}
Run Code Online (Sandbox Code Playgroud)

在hazelcast.xml文件中,我启用了TCP-IP连接并禁用了其他所有内容:

<network>
<port auto-increment="true">5701</port>
<join>
  <multicast enabled="false" />
  <tcp-ip enabled="true">
    <interface>192.168.0.01</interface>
    <interface>192.168.0.02</interface>
  </tcp-ip>
</join>
<interfaces enabled="false" />
<symmetric-encryption enabled="false" />
<asymmetric-encryption enabled="false" />
Run Code Online (Sandbox Code Playgroud)

我在两台机器上部署了应用程序,IP地址对应于.xml文件(192.168.0.01和192.168.0.02),当我从浏览器调用服务时它第一次工作(它锁定并返回"锁定" )每次我调用unlock()方法它都会正确返回(我得到字符串"unlocked")但是在第一次之后,每当我调用lock()方法时,我都会得到一个超时.它看起来不像unlock()方法解锁它.

有人能指出我使用分布式锁定与淡褐色的正确方法吗?

java locking hazelcast

3
推荐指数
1
解决办法
4022
查看次数

如果我在Tomcat上发出关闭命令,它会使用Spring Integration处理正在进行的所有消息

我们一直在讨论在使用Spring Integration进行处理时关闭tomcat的问题.

我们想知道Spring(Spring Integration)是否默认处理入站通道中正在进行的所有消息,然后才能告诉Tomcat它已准备好关闭?

我的预感是Spring容器将释放所有可用资源,包括阻止处理任何新的通道,然后告诉Tomcat它已准备好关闭.虽然只是一个想法,我需要做一些很好的研究.我们必须添加一些内容以确保使用Tomcat最好地关闭吗?

研究:到目前为止看起来像"火与遗忘"之类的东西存在,outbound channel adapter所以inbound channels可能包含同样的东西.

java spring-integration

3
推荐指数
1
解决办法
679
查看次数

我应该如何在Spring Integration中构建我的消息?

我有一个我编码的应用程序,我正在重构以更好地使用Spring Integration.应用程序处理文件的内容.

问题(我认为)是我当前的实现Files而不是MessagesSpring Integration Messages.


为了避免进一步滚动我自己的代码,我后来必须维护,我想知道是否有一个推荐的结构用于在Spring Integration中构造Messages.如果有一些推荐的组合是什么我不知道是channel喜欢的东西MessageBuilder,我应该使用.


流程/代码(最终)

我还没有配置它的代码,但我想最终得到以下组件/进程:

  1. 收到一个文件,删除文件的页眉和页脚,取每行并将其转换为Message<String> (这似乎实际上是一个Splitter)我发送到...
  2. 通道/端点向路由器发送消息
  3. 路由器在Payload中检测格式字符串并在此处路由到类似于Order Router的相应通道...
  4. 然后,所选通道构建适当类型的消息,特别是键入的消息.例如,我有以下构建器来构建消息...

    公共类ShippedBoxMessageBuilder实现CustomMessageBuilder {

    @Override public Message buildMessage(String input){ShippedBox shippedBox =(ShippedBox)ShippedBoxFactory.manufactureShippedFile(input); return MessageBuilder.withPayload(shippedBox).build(); } ...

  5. 消息按类型路由到适当的处理通道

我想要的解决方案似乎让我感到困惑.但是,我故意将两个任务分开1)将文件分成多行Messages<String>和2)转换Messages<String>Messages<someType>.因此,我认为我需要一个额外的路由器/消息构建器用于第二个任务.

java spring-integration

2
推荐指数
1
解决办法
4922
查看次数

弹簧单元/集成测试设置

我没有写单元或集成测试,但现在我正在尝试.我很难设置环境.

我在WEB-INF/applicationContext*.xml下有我的应用程序上下文,在我的applicationContext.xml中,它有一个对DB用户/传递,LDAP主机等的属性文件的引用

<bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>/WEB-INF/spring-config/dev.properties</value>
            </list>
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

我有另一个log4j配置属性(DEV/Staging/Production的diff配置).${webapp.root}在web.xml中定义

 <!-- log4j setting -->
    <bean id="log4jInitialization" 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>${webapp.root}/${log4j.properties.location}</value>
            </list>
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

现在我试图将以下内容放入测试类中.

@Override
protected String[] getConfigLocations() {
   return new String[]{
            "file:trunk/code/web/WEB-INF/applicationContext.xml",
        };
}
Run Code Online (Sandbox Code Playgroud)

这正确引用了我的xml,但所有属性都被搞砸了.

我想知道以下内容:

  • 有没有办法在测试类中正确设置?如果没有,我应该移动这些课程吗?
  • 如果存在仅存在于容器中的webroot的引用,我该如何设置Log4j?
  • Spring配置位置的最佳实践是什么?

请指教

谢谢

java junit spring log4j

1
推荐指数
1
解决办法
4150
查看次数

标签 统计

java ×6

log4j ×2

spring ×2

spring-integration ×2

hazelcast ×1

junit ×1

locking ×1

swing ×1

swt ×1