रनटाइम पर कुछ विकल्प सेट करते समय मुझे भी इसी तरह की समस्या थी। मैंने उन समस्याओं को एक कस्टम VelocityBuilder और बाहरी velocity.properties फ़ाइल को सफ़ेद कर दिया जहां आप सभी रनटाइम गुण डाल सकते हैं।
resource.loader = webinf, class
webinf.resource.loader.description = Framework Templates Resource Loader
webinf.resource.loader.class = applica.framework.library.velocity.WEBINFResourceLoader
webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader
webapp.resource.loader.path =
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path =
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
runtime.log='/pathYouWant/velocity.log'
: जहां मैं कुछ विन्यास डाल
in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties");
properties.load(in);
engine.init(properties);
तो मैं/वेब-INF में एक velocity.properties फ़ाइल है:
public class BaseVelocityBuilder implements VelocityBuilder {
private VelocityEngine engine;
private Log logger = LogFactory.getLog(getClass());
@Autowired
private WebApplicationContext webApplicationContext;
public VelocityEngine engine() {
if(engine == null) {
engine = new VelocityEngine();
Properties properties = new Properties();
InputStream in = null;
try {
in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties");
properties.load(in);
engine.init(properties);
} catch (IOException e) {
e.printStackTrace();
logger.error("Error loading velocity engine properties");
throw new ProgramException("Cannot load velocity engine properties");
}
IOUtils.closeQuietly(in);
}
return engine;
}
}
इस लाइन देखें: यहाँ कोड है अंत में आपके application.xml:
<bean class="applica.framework.library.velocity.BaseVelocityBuilder" />
इस तरह से आप विभिन्न अनुप्रयोगों के लिए उदाहरण के लिए अलग-अलग फ़ाइल लॉग कर सकते हैं और जब आप उत्पादन में युद्ध देते हैं, तो sysadm उत्पादन सर्वर के एनवी कॉन्फ़िगरेशन के कारण गुणों को बदल सकता है।
स्रोत
2014-10-20 14:11:40
यह मेरे लिए सही लग रहा है। क्या स्थान की सही अनुमतियां हैं? एक वैकल्पिक के रूप में, आप log4j का भी उपयोग कर सकते हैं और इसे अपने नियमित एप्लिकेशन लॉग में विलय कर सकते हैं। –