这个Spring JSON端点在Jboss/Tomcat中有什么用处?我试图将其添加到现有的应用程序,直到我开始重构代码,现在错误并没有指向任何对我来说合乎逻辑的东西。这个Spring JSON端点在Jboss/Tomcat中打破了什么?
这是我的代码控制器和助手类,保持干净。 Controller.Java
import java.io.IOException;
import java.util.Properties;
import javax.annotation.Nonnull;
import org.apache.commons.configuration.ConfigurationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class PropertiesDisplayController {
@Nonnull
private final PropertiesDisplayHelper propertiesHelper;
/**
* @param propertiesHelper
*/
@Nonnull
@Autowired
public PropertiesDisplayController(@Nonnull final PropertiesDisplayHelper propertiesHelper) {
super();
this.propertiesHelper = propertiesHelper;
}
@Nonnull
@RequestMapping("/localproperties")
public @ResponseBody Properties localProperties() throws ConfigurationException, IOException {
return propertiesHelper.getLocalProperties();
}
@Nonnull
@RequestMapping("/properties")
public @ResponseBody Properties applicationProperties() throws IOException,
ConfigurationException {
return propertiesHelper.getApplicationProperties();
}
}
这将是Helper.java
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import javax.annotation.Nonnull;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
public class PropertiesDisplayHelper {
/** Static location of properties in for SSO */
private static String LOCAL_PROPERTIES_LOCATION =
"local.properties";
/** Static strings for masking the passwords and blank values */
private static String NOVALUE = "**NO VALUE**";
/** Static strings for masking the passwords and blank values */
private static String MASKED = "**MASKED**";
@Nonnull
public Properties getApplicationProperties() throws ConfigurationException {
final Properties properties = new Properties();
final Configuration configuration = AppConfiguration.Factory.getConfiguration();
// create a map of properties
final Iterator<?> propertyKeys = configuration.getKeys();
final Map<String, String> sortedProperties = new TreeMap<String, String>();
// loops the configurations and builds the properties
while (propertyKeys.hasNext()) {
final String key = propertyKeys.next().toString();
final String value = configuration.getProperty(key).toString();
sortedProperties.put(key, value);
}
properties.putAll(sortedProperties);
// output of the result
formatsPropertiesData(properties);
return properties;
}
@Nonnull
public Properties getLocalProperties() throws ConfigurationException, IOException {
FileInputStream fis = null;
final Properties properties = new Properties();
// imports file local.properties from specified location
// desinated when the update to openAM12
try {
fis = new FileInputStream(LOCAL_PROPERTIES_LOCATION);
properties.load(fis);
} finally {
// closes file input stream
IOUtils.closeQuietly(fis);
}
formatsPropertiesData(properties);
return properties;
}
void formatsPropertiesData(@Nonnull final Properties properties) {
for (final String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
if (StringUtils.isEmpty(value)) {
value = NOVALUE;
} else if (key.endsWith("ssword")) {
value = MASKED;
} else {
value = StringEscapeUtils.escapeHtml(value);
}
// places data to k,v paired properties object
properties.put(key, value);
}
}
}
它们设置的属性的JSON显示在应用程序并从用于记录一个文件。但是现在这个没有侵入性的代码似乎破坏了我的整个应用程序构建。
下面是从Jboss的
误差20:33:41559 ERROR [org.jboss.as.server](DeploymentScanner线程 - 1)JBAS015870:部署部署 “openam.war” 的用回滚以下失败消息: {“JBAS014671:Failed services”=> {“jboss.deployment.unit。\”APPLICATION.war \“。STRUCTURE”=>“org.jboss.msc.service.StartException in service jboss.deployment .UNIT。\“APPLICATION.war \”。结构:JBAS018733:无法处理部署结构部署\“APPLICATION.war \” 导致:org.jboss.as.server.deployment.DeploymentUnitProcessingException:JBAS018740:无法安装部署内容 导致:java.io.FileNotFoundException:APPLICATION.war(Ac塞斯被拒绝)“}}
,并从Tomcat
的错误,我在这里丢失,觉得有什么我只是不明白。
似乎更多的是配置问题,而不是编码问题。你能发布一些你的相关配置文件吗? – EricF
Spring配置像XML文件或服务器配置像Jboss/Tomcat? – whatkai