gpt4 book ai didi

java - Tomcat 404 : The requested resource is not available

转载 作者:行者123 更新时间:2023-11-28 23:35:20 27 4
gpt4 key购买 nike

我正在尝试创建简单的 RESTful Web 服务。我的 war 文件构建成功,并且在 tomcat 上启动时没有错误。

但是,当我调用某些服务时,例如 http://localhost:8080/fxmonitor/service/account/,我给出错误:类型状态报告信息描述请求的资源不可用。

在 tomcat 日志中:10.08.2014 14:31:07 org.springframework.web.servlet.DispatcherServlet noHandlerFound警告:在名为“FxMonitor”的 DispatcherServlet 中未找到具有 URI [/fxmonitor/service/account/Hello world1FUUUUU] 的 HTTP 请求的映射

我的 web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>Fx pamm monitor</display-name>
<description>Some desc</description>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:context.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>FxMonitor</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:app-context.xml</param-value>
</init-param>
<!--<load-on-startup>1</load-on-startup>-->
</servlet>
<servlet-mapping>
<servlet-name>FxMonitor</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

应用程序上下文.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<!--
- DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">

<context:component-scan
base-package="com.pammonitor.web"/>

<mvc:annotation-driven />
<!--<mvc:resources mapping="/resources/**" location="/resources/"/>-->

</beans>

<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/fxmonitor"
p:username="root" p:password="0000" />

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fxpammunit" />
<property name="dataSource" ref="dataSource" />
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.weaving" value="false"/>
</map>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config />
<context:component-scan base-package="com.pammonitor"/>
<context:component-scan base-package="com.pammonitor.dao.impl" />

</beans>

账户 Controller :

package com.pammonitor.web;

/**
* Created by user on 10.08.14.
*/

import com.pammonitor.dao.AccountDAO;
import com.pammonitor.entity.AccountEntity;
import com.pammonitor.model.AccountModel;
import org.eclipse.persistence.annotations.ChangeTracking;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

@Controller
@RequestMapping("/service/account/")
public class AccountController {

@RequestMapping(method= RequestMethod.GET)
public String getAccount(){
return "Hello world1FUUUUU";
}

public AccountDAO getAccountDAO() {
return accountDAO;
}

public void setAccountDAO(AccountDAO accountDAO) {
this.accountDAO = accountDAO;
}
}

最佳答案

所以我通过在方法中添加@ResponseBody解决了这个问题:

@RequestMapping(method= RequestMethod.GET)
public @ResponseBody String getAccount(){
return "Hello world1FUUUUU";
}

关于java - Tomcat 404 : The requested resource is not available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25227775/

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