使用
static {
/** Initialisation du moteur velocity */
Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.NullLogSystem");
Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER,
EjbConstants.VELOCITY_RESOURCE_LOADER_TYPE);
Velocity.setProperty(EjbConstants.VELOCITY_CLASSPATH_RESOURCE_LOADER,
ClasspathResourceLoader.class.getName());
}
public static String createXMLFlux(final RemiseEffetBean bean,
final String maquetteId) {
try {
final VelocityContext context = new VelocityContext();
final StringWriter swOut = new StringWriter();
// Initialisation
Velocity.init();
final Template template = Velocity.getTemplate(
EjbConstants.XML_TEMPLATE_FILE, CharEncoding.UTF_8);
context.put(EjbConstants.VELOCITY_REMISE_EFFET, bean);
// id de la maquette pdf a generer
context.put(EjbConstants.VELOCITY_MAQUETTE_ID, maquetteId);
template.merge(context, swOut);
return swOut.toString();
} catch (final ResourceNotFoundException e) {
LOGGER.error("La template n'a pas été trouvée", e);
} catch (final ParseErrorException e) {
LOGGER.error("Erreur du parsing de la template", e);
} catch (final MethodInvocationException e) {
LOGGER.error("Erreur lors de la substitution des données", e);
} catch (final Exception e) {
LOGGER.error("Erreur lors du traitement du fichier", e);
}
return null;
}
加入 properties.setProperty \t \t( 「runtime.log.logsystem.class」 \t \t「org.apache.velocity。 runtime.log.NullLogSystem「); 訣竅 – 2009-10-18 23:38:05
@Hamza:非常感謝!將此設置添加到velocity.properties解決了問題 – Vanya 2009-12-08 08:01:52