繁体   English   中英

AngularJs不会从本地“ Maven Project”加载JSON文件

[英]AngularJs doesn't load JSON file from local “Maven Project”

我正在使用AngularJs构建Web应用程序,试图对我的应用程序使用angular-translate。 这是Doc: http : //www.ng-newsletter.com/posts/angular-translate.html

$translateProvider.useStaticFilesLoader({
  prefix: 'assets/resources/',
  suffix: '.json'
});

我的项目目录中有2个json文件

webapp/assets/resources/locale-en_US.json
webapp/assets/resources/locale-ru_RU.json

当我在浏览器中运行我的应用程序时,出现此错误

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:8080/assets/resources/locale-ru_RU.json

我试图从json文件所在的目录中加载.js文件和.jpg文件

webapp/assets/resources/foo.jpg

一切正常,我无法从本地仅加载JSON文件。 我试图发出$ http请求,但没有结果。

$http.get('assets/resources/locale-en_US.json' ).success(function(data) {
   console.log(data);
});

看起来我的项目忽略了本地的json文件。 我进行了研究,并提出了一些将映射添加到web.xml的建议。 没有结果

<mime-mapping>
  <extension>json</extension>
  <mime-type>application/json</mime-type>
</mime-mapping>

知道该怎么办吗?

此致Gari.E

我的web.xml中servlet映射

<servlet-mapping>
    <servlet-name>shemoGeServlet</servlet-name>
    <url-pattern>*.json</url-pattern>
</servlet-mapping>

WEB-INF目录中搜索jsno文件,但是我的jsno文件在资产目录中。 这是我的servlet-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven/>

    <mvc:resources location="/assets" mapping="/assets/**"/>

    <context:component-scan base-package="ge.shemo"/>

     <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManager">
                <constructor-arg>
                    <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
                        <constructor-arg>
                            <map>
                                <entry key="json" value="application/json"/>
                                <entry key="xml" value="application/xml"/>
                            </map>
                        </constructor-arg>
                    </bean>
                </constructor-arg>
            </bean>
        </property>


        <property name="defaultViews">
            <list>
                <!-- JSON View -->
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg>
                        <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
                            <property name="autodetectAnnotations" value="true" />
                        </bean>
                    </constructor-arg>
                </bean>
            </list>
        </property>
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages"></bean>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>

</beans>

这就是为什么我越来越

Failed to load resource: the server responded with a status of 404 (Not Found) 

我删除了servlet,问题消失了

<servlet-mapping>
    <servlet-name>shemoGeServlet</servlet-name>
    <url-pattern>*.json</url-pattern>
</servlet-mapping>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM