Spring RequestMapping错误:服务器响应状态为404(未找到)

时间:2015-11-10 14:14:12

标签: javascript java spring spring-mvc

我有一个Spring的问题,我需要在执行ajax调用时调用一个方法但是,每次尝试调用时,我都会遇到同样的错误:

http://localhost:8080/portaleConservazione/service/rest/enti/management Failed to load resource: the server responded with a status of 404 (Not Found)

这是我的代码: 爪哇:

@RestController
public class RestGestioneEnti extends RestApiBaseController {

@Autowired
private GenericDao genericDao;

@RequestMapping(value = "/enti/management", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("token") String token,
        @RequestParam("id") int idEnte,
        @RequestParam("action") String action,
        @RequestParam("entetype") int enteType,
        @RequestParam("ipa") String codiceIpaEnte,
        @RequestParam("localita") String localita,
        @RequestParam("ente_terze_tipo") String enteTerzeTipo,
        @RequestParam("ente_terze_bool") String gesinf,
        @RequestParam("presa_in_carico") String presaInCarico,
        @RequestParam("ragionesociale") String ragioneSociale,
        @RequestParam("indirizzo") String indirizzo,
        @RequestParam("cap") String cap,
        @RequestParam("comune") String comune,
        @RequestParam("piva") String partitaIva,
        @RequestParam("codiceipa") String codiceIpaMacroEnte,
        @RequestParam("path_fattura") String pathContabilitaFattura,
        @RequestParam("url_conservazione") String urlConservazione,
        @RequestParam("in_modifica") String inModificaString,
        @RequestParam("idFatt") String idFattura,
        @RequestParam("macro") String macro,
        @RequestParam("idAmm") String idAmm,
        @RequestParam("idUtente") String idUtente,
        @RequestParam("nomemacroente") String nomeMacroEnte,
        @RequestParam("idPadre") String idPadre,
        @RequestParam("nomeSer") String nomeSer,
        @RequestParam("prot_auto_bool") String extProt,
        @RequestParam("logo_ente") MultipartFile file) {

使用Javascript:

$.ajax({
        type : "POST",
        url : '../service/rest/enti/management',
        contentType : 'application/json; charset=utf-8',
        data : {"id" : idEnte, "action" : action, "token" : token},
        success : function(obj, textstatus) {
            obj = obj.trim();
            var json = JSON.parse(obj);
            if (obj.stato == 'error') {
                alert('Errore');
            } else {
                $(json.data).each(function() {
                    $(idSelectServizio).append($('<option>', {
                        value : this.idente,
                        text : this.ragionesociale,
                        data : {
                            idamm : this.idamm
                        }
                    }));
                });
                if ($(json.data).length > 0) {
                    $('#ricercaConFiltroIdAmmNonCongruo').show();
                } else {
                    $('#ricercaConFiltroIdAmmNonCongruo').hide();
                }
            }
        },
        error : function(obj, textstatus) {
            alert('Errore di comunicazione col server!');
        }
    });

Spring dispatcher-servlet:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<context:component-scan base-package="it.unimaticaspa.spring" />
<context:annotation-config />

<mvc:annotation-driven />

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


<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

    <!-- one of the properties available; the maximum file size in bytes -->
    <property name="maxUploadSize" value="30000000" />

</bean>

<!-- <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" 
    destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" 
    /> <property name="url" value="${jdbc.url}" /> <property name="username" 
    value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" 
    /> </bean> -->
<!-- bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="java:comp/env/jdbc/portale_pa" /> </bean -->

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/portale_pa"
    resource-ref="true" />

<context:property-placeholder location="classpath:jdbc.properties" />

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="it.unimaticaspa.spring.hibernate.model" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
        </props>
    </property>
</bean>

<tx:annotation-driven />

<!-- gestione transazioni -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="persistenceExceptionTranslationPostProcessor"
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />


<!-- gestione dei task tramite annotation -->
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="2" />
<task:annotation-driven executor="taskExecutor"
    scheduler="taskScheduler" />

<bean id="uninotificheServiceBeanServiceStub"
    class="it.unimaticaspa.spring.axis.factory.UninotificheServiceBeanServiceStubFactoryBean"
    scope="singleton">
    <!-- this next element effects the proxying of the surrounding bean, needed 
        because .... will try to set the stub out of request scope -->
    <aop:scoped-proxy />
    <constructor-arg index="0">
        <!-- The WS stub is created here, and passed to the factory-method of 
            ... as a parameter -->
        <bean
            class="it.unimaticaspa.spring.externalservice.uninotifica.stub.UninotificheServiceBeanServiceStub"
            scope="prototype">
            <constructor-arg ref="axisConfigContext" />
        </bean>
    </constructor-arg>
</bean>


<bean id="gestioneBlocchiWebServiceBeanServiceStub"
    class="it.unimaticaspa.spring.axis.factory.GestioneBlocchiWebServiceBeanServiceStubFactoryBean"
    scope="singleton">
    <!-- this next element effects the proxying of the surrounding bean, needed 
        because .... will try to set the stub out of request scope -->
    <aop:scoped-proxy />
    <constructor-arg index="0">
        <!-- The WS stub is created here, and passed to the factory-method of 
            ... as a parameter -->
        <bean
            class="it.unimaticaspa.spring.service.provaconservazione.wsstub.GestioneBlocchiWebServiceBeanServiceStub"
            scope="prototype">
            <constructor-arg ref="axisConfigContext" />
        </bean>
    </constructor-arg>
</bean>


<!-- Exists to avoid deployment of axis jar into temp dir for each request. 
    See AXIS2-3919 for more details. -->
<bean id="axisConfigContext" class="org.apache.axis2.context.ConfigurationContextFactory"
    factory-method="createConfigurationContextFromFileSystem">
    <constructor-arg index="0">
        <null />
    </constructor-arg>
    <constructor-arg index="1">
        <null />
    </constructor-arg>
</bean>

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我解决了以这种方式更改函数的参数

爪哇:

@RequestMapping(value = "enti/management", method = RequestMethod.POST)
public String manageEntiRicerca(@RequestBody String payload) throws Exception {

    JSONObject json = new JSONObject(payload);

使用Javascript:

var payload = {
    "idFatt" : idFattura,
    "action" : action,
    "token" : token
};
var fat = idFattura;
$.ajax({
    type : "POST",
    url : '../service/rest/enti/management,
    contentType : 'application/json; charset=utf-8',
    data : JSON.stringify(payload),
    resourceType : 'json',
    success : function(obj, textstatus) {
        obj = obj.trim();
        var json = JSON.parse(obj);
        // parse response
        var res = json.useExtProt;
        action_accept_api(fat, res);
    },
    error : function(request, status, error) {
        alert('errore');
    }
});

现在正常运作