3

我在尝试部署我的 portlet 时遇到了一个非常奇怪的问题。

日志中显示的错误是:

Context initialization failed
java.lang.IllegalArgumentException: class myPackage.SqlTimestampPropertyEditor is not assignable to interface java.beans.PropertyEditor
at org.springframework.util.Assert.isAssignable(Assert.java:368)
    at org.springframework.util.Assert.isAssignable(Assert.java:351)
    at org.springframework.beans.factory.config.CustomEditorConfigurer.postProcessBeanFactory(CustomEditorConfigurer.java:199)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:664)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

这是我的属性编辑器:

 package myPackage;

 import myPackage.util.Util;
 import java.beans.PropertyEditorSupport;
 import java.sql.Timestamp;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;

public class SqlTimestampPropertyEditor extends PropertyEditorSupport {

public static final String TIMESTAMP_BATCH_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
private final SimpleDateFormat sdf;

/**
 * uses default pattern yyyy-MM-dd for date parsing.
 */
public SqlTimestampPropertyEditor() {
    this.sdf = new SimpleDateFormat(SqlTimestampPropertyEditor.TIMESTAMP_BATCH_PATTERN);
}

/**
 * Uses the given pattern for dateparsing, see {@link SimpleDateFormat} for
 * allowed patterns.
 *
 * @param pattern the pattern describing the date and time format
 * @see SimpleDateFormat#SimpleDateFormat(String)
 */
public SqlTimestampPropertyEditor(SimpleDateFormat dateFormat) {
    this.sdf = dateFormat;
}

/**
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public final void setAsText(String text) throws IllegalArgumentException {

    try {
        if (!Util.emptyString(text)) {
            setValue(new Timestamp(this.sdf.parse(text).getTime()));
        }
    } catch (ParseException ex) {
        throw new IllegalArgumentException("Non se pudo parsear o timestamp: " + ex.getMessage(), ex);
    }
}

/**
 * Format the Timestamp as String, using the specified DateFormat.
 */
@Override
public final String getAsText() {
    Timestamp value = (Timestamp) getValue();
    return (value != null ? this.sdf.format(value) : "");
}
}

最奇怪的是,这种情况有时会发生,它会自行解决,并且日志显示“PortalPack 消息:已成功部署”。但是我无法将 portlet 添加到 webspace,即使我可以看到它已部署到 glassfish 控制台中。

这对我来说没有任何意义,我真的很感谢在这个问题上提供任何帮助......在此先感谢!

4

0 回答 0