我的项目中缺少什么注释?
What annotation am I missing in my project?
我已经阅读了类似的问题,但找不到解决方案。
我正在使用 Vaadin 和 Spring Boot。我有一个以前的项目 运行 很好,但没有收到此白标签消息,我使用相同的注释和所有内容。在入口点 Spring Boot class 我定义了 @SpringBootApplication.
“此应用程序没有针对 /error 的显式映射,因此您将其视为后备。
12 月 28 日星期六 18:56:32 CET 2019
出现意外错误(类型=未找到,状态=404)。
没有可用的消息
同时我认为问题出在我的POM上。
感谢您的帮助,下次不再犯同样的问题。
我的服务class:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component
public class PersonService {
@Autowired
private JdbcTemplate JdbcTemplate;
public List<Person>
findAll() {
return JdbcTemplate.query(
"SELECT Név, Mérkőzések_száma, Győzelmek_száma, Vereségek_száma FROM Darts",
(rs, rowNum) -> new Person(rs.getString("nev"),
rs.getInt("games"), rs.getInt("wins"), rs.getInt("loses")));
}
public void update(Person person) {
JdbcTemplate.update(
"UPDATE Darts SET Mérkőzések_száma=?, Győzelmek_száma=?, Vereségek_száma=? WHERE Név=?)",
person.getGames(), person.getWins(), person.getLoses(), person.getName());
}
}
我的人class:
public class Person {
private String name;
private int games;
private int wins;
private int loses;
public Person(String name, int games, int wins, int loses) {
this.name = name;
this.games = games;
this.wins = wins;
this.loses = loses;
}
public int getLoses() {
return loses;
}
public void setLoses(int loses) {
this.loses = loses;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getGames() {
return games;
}
public void setGames(int games) {
this.games = games;
}
public int getWins() {
return wins;
}
public void setWins(int wins) {
this.wins = wins;
}
}
我的主视图class:
import com.vaadin.data.Binder;
import com.vaadin.flow.router.Route;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;
import com.vaadin.spring.annotation.SpringUI;
import org.springframework.beans.factory.annotation.Autowired;
@SpringUI
public class MainView extends UI {
@Autowired
private PersonService service;
private TextField name = new TextField("Name");
private TextField games = new TextField("Game");
private TextField wins = new TextField("Win");
private TextField loses = new TextField("Lose");
private Person person;
private final Binder<Person> bind = new Binder<>(Person.class);
private final Grid<Person> grid = new Grid<>(Person.class);
@Override
protected void init(VaadinRequest request) {
grid.setColumns("name", "games", "wins", "loses");
VerticalLayout layout = new VerticalLayout(grid, name, games, wins, loses);
setContent(layout);
}
}
POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.benjaminhalasz</groupId>
<artifactId>darts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>darts</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<vaadin.version>14.1.3</vaadin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
已编辑:
application.properties:
spring.datasource.url=jdbc:mysql://localhost/vizsgadb_HB
spring.datasource.username=vizsgauser_HB
spring.datasource.password=12345678
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
经过一番研究,似乎是:
- 在您的 POM 中,您应该删除依赖项
vaadin-spring
。它与 vaadin-spring-boot-starter
导入的版本不同。使用启动器时,请尝试仅使用启动器,不要使用其他任何东西。它们旨在承载您需要的所有依赖项。
- 您应该将@SpringUI 替换为@Route。有关更多信息,请查看:https://www.baeldung.com/spring-boot-vaadin
让我知道这是否有效。
我已经阅读了类似的问题,但找不到解决方案。
我正在使用 Vaadin 和 Spring Boot。我有一个以前的项目 运行 很好,但没有收到此白标签消息,我使用相同的注释和所有内容。在入口点 Spring Boot class 我定义了 @SpringBootApplication.
“此应用程序没有针对 /error 的显式映射,因此您将其视为后备。
12 月 28 日星期六 18:56:32 CET 2019 出现意外错误(类型=未找到,状态=404)。 没有可用的消息
同时我认为问题出在我的POM上。
感谢您的帮助,下次不再犯同样的问题。
我的服务class:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component
public class PersonService {
@Autowired
private JdbcTemplate JdbcTemplate;
public List<Person>
findAll() {
return JdbcTemplate.query(
"SELECT Név, Mérkőzések_száma, Győzelmek_száma, Vereségek_száma FROM Darts",
(rs, rowNum) -> new Person(rs.getString("nev"),
rs.getInt("games"), rs.getInt("wins"), rs.getInt("loses")));
}
public void update(Person person) {
JdbcTemplate.update(
"UPDATE Darts SET Mérkőzések_száma=?, Győzelmek_száma=?, Vereségek_száma=? WHERE Név=?)",
person.getGames(), person.getWins(), person.getLoses(), person.getName());
}
}
我的人class:
public class Person {
private String name;
private int games;
private int wins;
private int loses;
public Person(String name, int games, int wins, int loses) {
this.name = name;
this.games = games;
this.wins = wins;
this.loses = loses;
}
public int getLoses() {
return loses;
}
public void setLoses(int loses) {
this.loses = loses;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getGames() {
return games;
}
public void setGames(int games) {
this.games = games;
}
public int getWins() {
return wins;
}
public void setWins(int wins) {
this.wins = wins;
}
}
我的主视图class:
import com.vaadin.data.Binder;
import com.vaadin.flow.router.Route;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;
import com.vaadin.spring.annotation.SpringUI;
import org.springframework.beans.factory.annotation.Autowired;
@SpringUI
public class MainView extends UI {
@Autowired
private PersonService service;
private TextField name = new TextField("Name");
private TextField games = new TextField("Game");
private TextField wins = new TextField("Win");
private TextField loses = new TextField("Lose");
private Person person;
private final Binder<Person> bind = new Binder<>(Person.class);
private final Grid<Person> grid = new Grid<>(Person.class);
@Override
protected void init(VaadinRequest request) {
grid.setColumns("name", "games", "wins", "loses");
VerticalLayout layout = new VerticalLayout(grid, name, games, wins, loses);
setContent(layout);
}
}
POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.benjaminhalasz</groupId>
<artifactId>darts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>darts</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<vaadin.version>14.1.3</vaadin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
已编辑: application.properties:
spring.datasource.url=jdbc:mysql://localhost/vizsgadb_HB
spring.datasource.username=vizsgauser_HB
spring.datasource.password=12345678
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
经过一番研究,似乎是:
- 在您的 POM 中,您应该删除依赖项
vaadin-spring
。它与vaadin-spring-boot-starter
导入的版本不同。使用启动器时,请尝试仅使用启动器,不要使用其他任何东西。它们旨在承载您需要的所有依赖项。 - 您应该将@SpringUI 替换为@Route。有关更多信息,请查看:https://www.baeldung.com/spring-boot-vaadin
让我知道这是否有效。