gpt4 book ai didi

java - 这个 Spring JSON 端点在 Jboss/Tomcat 中有什么问题?

转载 作者:行者123 更新时间:2023-11-28 23:31:10 26 4
gpt4 key购买 nike

这个 Spring JSON 端点在 Jboss/Tomcat 中有什么问题?我试图将它添加到现有的应用程序中,它一直有效,直到我开始重构代码,现在错误不指向任何对我来说合乎逻辑的东西。

这是我的代码,一个 Controller 和 Helper 类,以保持整洁。 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:41,559 错误 [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS015870:部署“openam.war”的部署已回滚,并显示以下失败消息:{"JBAS014671: 服务失败"=> {"jboss.deployment.unit.\"APPLICATION.war\".STRUCTURE"=> "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"APPLICATION .war\".STRUCTURE: JBAS018733: 无法处理部署\"APPLICATION.war\"的阶段结构 原因:org.jboss.as.server.deployment.DeploymentUnitProcessingException:JBAS018740:无法安装部署内容 引起:java.io.FileNotFoundException:APPLICATION.war(访问被拒绝)"}}

以及来自 Tomcat 的错误

http://pastebin.com/PXdcpqvc

我在这里迷路了,觉得有些东西我只是看不到。

最佳答案

一个简单的解决方案就在眼前。缺少的组件是辅助类上的 @Component 注释。

关于java - 这个 Spring JSON 端点在 Jboss/Tomcat 中有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30249827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com