小编Tri*_*ick的帖子

Java自定义记录器:记录标准或/和最佳实践

我正在开发一个框架,我不会尽可能轻量级和独立.

所以我写了我的日志记录类:

import java.util.Date;
import java.util.Properties;

public class Logger {

    private static final Logger me = new Logger();
    private static boolean info = false;
    private static boolean debug = false;
    private static boolean error = false;
    private static String className = null;

    public static Logger getInstance(Class<?> clazz) {  
        className = clazz.getCanonicalName();
        try {
            Properties props = new CustProps().load(clazz);
            if(props.get(CustProps.NAME_LOG_MODE) != null) {
                String devMode = props.getProperty(CustProps.NAME_LOG_MODE)
                                   .toLowerCase();
                if("info".equals(devMode)) {
                    info = true;
                    debug = true;
                } else if("debug".equals(devMode)) {
                    debug …
Run Code Online (Sandbox Code Playgroud)

java logging

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

在ContextLoaderListener中获取服务器名称

我的监听器正在填充Cache(Terracota),如果在应用程序启动时出现问题,则抛出ExceptionInInitializerError.我想获取服务器名称(如在HttpServletRequest - getServerName()上)以了解这发生的位置.

我怎么才能得到这个信息?

import javax.servlet.ServletContextEvent;

import net.f.core.service.util.CacheUtil;

import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;

/**
 * Application Lifecycle Listener implementation class OnContextLoadListener
 * 
 */
public class OnContextLoadListener extends ContextLoaderListener {

private static final Logger log = Logger
        .getLogger(OnContextLoadListener.class);

@Override
public void contextDestroyed(
        @SuppressWarnings("unused") ServletContextEvent sce) {
    // nothing here
}

@Override
public void contextInitialized(
        @SuppressWarnings("unused") ServletContextEvent sce) {

    try {
        CacheUtil.getInstance();
    } catch (ExceptionInInitializerError e) {
        log.error("Problem with application start!", e);
        // notify me
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring request listener

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

Maven和Eclipse问题 - 寻找资源

我有一个问题,maven正在Eclipse安装文件夹中寻找资源.

它说:

This file was not found: file:/C:/eclipse/eclipse/src/main/resources/config/spring/applicationContext.xml
Run Code Online (Sandbox Code Playgroud)

我的工作区在c:/Work/Core/里面和里面src/main/resources.

是否有任何pom.xml配置,以使其看起来相对于它的位置?

编辑#1:

我从Eclipse运行Maven.从命令行编译没有问题.

我正在尝试运行Junit测试.

编辑#2:

所有依赖项,web.xml,...都可以 - 我知道这是因为其他开发人员在Linux和Idea上使用相同的文件,项目正在运行中没有问题.使用我的项目设置junit测试不起作用,编译wsdl文件不起作用 - 因为它无法找到资源.

编辑#3:

找到了答案 - 它在这里发布了.

java eclipse directory resources maven

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

Spring邮件支持 - 没有主题

我已经更新了我的库,现在发送的电子邮件没有主题.我不知道这发生在哪里......

Mail API是1.4.3.,Spring 2.5.6.和Spring Integration Mail 1.0.3.RELEASE.

<!-- Definitions for SMTP server -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="${mail.host}" />
    <property name="username" value="${mail.username}" />
    <property name="password" value="${mail.password}" />
</bean>

<bean id="adminMailTemplate" class="org.springframework.mail.SimpleMailMessage" >
    <property name="from" value="${mail.admin.from}" />
    <property name="to" value="${mail.admin.to}" />
    <property name="cc">
        <list>
            <value>${mail.admin.cc1}</value>
        </list>
    </property>
</bean>

<!-- Mail service definition -->
<bean id="mailService" class="net.bbb.core.service.impl.MailServiceImpl">
    <property name="sender" ref="mailSender"/>
    <property name="mail" ref="adminMailTemplate"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

和属性mail.host,mail.username,mail.password,mail.admin.from,mail.admin.to,mail.admin.cc1.

Java类:

/** The sender. */
private MailSender sender;

/** The mail. */
private SimpleMailMessage mail;

public …
Run Code Online (Sandbox Code Playgroud)

java email spring

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

更改pom.xml不会更新Eclipse中的库

我有像这样的pom.xml:

...

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>

<dependencies>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

...
Run Code Online (Sandbox Code Playgroud)

当我spring.version换成3.2.2.RELEASE时,没有任何反应.我仍然在Libraries构建路径下有3.0.5.RELEASE.

我正在使用带有m2eclipse的Eclipse Indigo SR2.

编辑:请注意,我是maven世界的新手.

eclipse m2eclipse pom.xml maven

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

Android长按滚动

我想用滚动"连接"长按,因此用户不必释放屏幕并开始滚动.

我有手势探测器实现...

final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
    public void onLongPress(MotionEvent e) {
        // action 1
    }

    public boolean onScroll(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
        // action 2
    }       
}

public boolean onTouchEvent(MotionEvent event) {
    return gestureDetector.onTouchEvent(event);
}    
Run Code Online (Sandbox Code Playgroud)

但是现在在动作1和动作2之间,用户必须释放屏幕......如何在不释放屏幕的情况下连接此动作?

android scroll long-press

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

Android drawables - 使用xhdpi for hdpi

最后两个问题没有答案,我希望"第三个的魅力"工作:)

我希望HDPI应用程序在"drawable-xhdpi"文件夹中使用那些drawable,在"drawable-mdpi"中使用LDPI设备.所以我不必复制相同的图像.这可能吗?

android dpi drawable hdpi

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