Не работают REST запросы, те при переходе на http://localhost:8080/ появляется HTTP Status 404 – Not Found, хотя я ожидаю увидеть табличку с данными из таблицы БД MainController.java:
package com.NGTUProj.GS.Controller;
import ...
@RestController
@ComponentScan("com.NGTUProj.GS")
public class MainController {
private final ClientService clientService;
public MainController(ClientService clientService) {
this.clientService = clientService;
}
@RequestMapping(value = "", method = RequestMethod.GET)
public String index(ModelMap model) {
model.addAttribute("clients", clientService.getAll());
return "index";
}
@RequestMapping(value = "/client/create", method = RequestMethod.POST)
public String createClient(@RequestParam("name") String name, @RequestParam("email") String email, @RequestParam("telephone") String telephone) {
clientService.addClient(new ClientEntity(name, email, telephone));
return "redirect :/";
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>GameShop</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring-context.xml</param-value>
</context-param>
</web-app>
spring-context.xml:
<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:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- Конфигурация Spring -->
<context:component-scan base-package="com.NGTUProj.GS"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/View/"/>
<property name="suffix" value=".jsp"/>
</bean>`
<!-- Настройка подключения к БД -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/gameshop?useSSL=false"
p:user="root"
p:password="password"
/>
<bean id = "entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan" value="com.NGTUProj.GS.Entity" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="persistenceUnitName" value="item-manager-pu"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="jpaDialect" ref="jpaDialect"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<jpa:repositories base-package="com.NGTUProj.GS.Repository"/>
</beans>
index.jsp:
<%@ page language="java" pageEncoding="UTF-8" session="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head lang="en">
<title>GameShop</title>
</head>
<body>
<div id="main">
<div id="dialog">
<br><br><table>
<tr>
<th>Name</th>
<th>email</th>
<th>telephone</th>
<th>orders</th>
</tr>
<c:forEach items="${clients}" var="client" varStatus="status">
<tr valign="top">
<td>${client.getName()}</td>
<td>${client.getEmail()}</td>
<td>${client.getTelephone()}</td>
<td><a href="${pageContext.servletContext.contextPath}/get_orders_by_id?id=?${client.id}">list orders</a>
</tr>
</c:forEach>
</table>
</div>
</div>
</div>
</body>
</html>
Структура проекта: (класс Main никак не учавствует, нужен был только для проверки Entity, запускается через TomCat, Application Context: /)
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(ModelMap model) {
...
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Возникает ошибка Exception in thread "main" javalang
Я создаю приложение и конекчу его с сервером через AsyncTask каждый определенный отрезок времени с помощью AlarmManager и проблема в том что на android...