2015-11-05 3 views
1

Я создаю веб-приложение с помощью AngularJs, пытаясь использовать угловой перевод для своего приложения. Вот Doc: http://www.ng-newsletter.com/posts/angular-translate.htmlAngularJs не загружает JSON-файл из локального «Maven Project»

$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 

Я попытался загрузить .js файл, а также .jpg из той же директории, где находится мой JSon файлы

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

+0

, что местоположение файла JS делает $ http.get()? – charliefarley321

+0

Я нашел решение своей проблемы, спасибо :) –

ответ

0

Я имел сервлет-отображение в моем web.xml

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

который искал jsno файлов в WEB-INF каталога, но мои jsno файлов были в активов. Вот мой сервлет-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-mapping> 
    <servlet-name>shemoGeServlet</servlet-name> 
    <url-pattern>*.json</url-pattern> 
</servlet-mapping> 
Смежные вопросы