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

标签 java spring spring-mvc tomcat jboss

这个 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/

相关文章:

java - 我需要为偶数和赔率得到两条单独的线,但要注意的是,我只能使用一个 while 循环

spring - 通过枚举在 Spring MVC 中选择

java - 覆盖 spring-boot EurekaInstanceConfigBean

html - 使用 th :href 在 spring mvc 中引用带有 thymeleaf 的 .css 文件

Java字符串停止转义字符 Action

java - 如何在数组中转换列表?在 java

java - Tomcat 服务器和 HTTP 客户端接受过期的自签名证书

java - Spring 3.2 MVC - 无法将 URL 与 Controller 匹配

java - 无法转发到请求的错误页面...因为已经提交了响应。结果,响应可能有错误的状态码

spring - JPA 中通过 ID 和版本删除对象