我有这个问题,想通过NetBeans解决它,我仍然不知道如何从提示符中使用maven,我找到了一个解决方案,但它是从提示符中找到的,有人知道怎么做吗?谢谢
原因:java.lang.ClassCast异常:类java.util.无法将$list12强制转换为类br.edu.iff.projetoEstoque.model.FuncionarioResp(java.util.ImMutableCollection$list12位于loader'bootstrap'的模块java.base中;br.edu.iff.projetoEstoque.model.FuncionarioResp位于loader的未命名模块中org.springframework.boot.devtools.restart.classloader.RestartClassLoader@35b254b3)
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-05 21:31:38.175 ERROR 15452 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-2.4.4.jar:2.4.4]
at br.edu.iff.projetoEstoque.ProjetoEstoqueApplication.main(ProjetoEstoqueApplication.java:32) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.4.jar:2.4.4]
Caused by: java.lang.ClassCastException: class java.util.ImmutableCollections$List12 cannot be cast to class br.edu.iff.projetoEstoque.model.FuncionarioResp (java.util.ImmutableCollections$List12 is in module java.base of loader 'bootstrap'; br.edu.iff.projetoEstoque.model.FuncionarioResp is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @74b715ff)
at br.edu.iff.projetoEstoque.ProjetoEstoqueApplication.run(ProjetoEstoqueApplication.java:75) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:806) ~[spring-boot-2.4.4.jar:2.4.4]
... 10 common frames omitted
2021-04-05 21:31:38.204 INFO 15452 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2021-04-05 21:31:38.204 INFO 15452 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-04-05 21:31:38.204 INFO 15452 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2021-04-05 21:31:38.219 INFO 15452 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 12.710 s
Finished at: 2021-04-05T21:31:39-03:00
------------------------------------------------------------------------
package br.edu.iff.projetoEstoque.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import org.hibernate.validator.constraints.Length;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class FuncionarioResp extends Funcionario{
@Column(length = 10,nullable = false)
@NotBlank(message = "Usuário obrigatório.")
@Length(max = 10,message = "Usuário deve ter no máximo 10 caracteres.")
private String usuario;
@Column(length = 6,nullable = false)
@NotBlank(message = "Senha obrigatória.")
@Length(max = 6, min = 6, message ="A senha deve conter 6 caracteres.")
private String senha;
@JsonIgnore
@OneToMany(mappedBy = "funcionarioresp")
@Valid
private List<Entrada> entradas = new ArrayList<>();
@JsonIgnore
@OneToMany(mappedBy = "funcionarioresp")
@Valid
private List<Despache> despaches = new ArrayList<>();
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public List<Entrada> getEntradas() {
return entradas;
}
public void setEntradas(List<Entrada> entradas) {
this.entradas = entradas;
}
public List<Despache> getDespaches() {
return despaches;
}
public void setDespaches(List<Despache> despaches) {
this.despaches = despaches;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public FuncionarioResp() {
}
}
添加此存储库时出现错误。
package br.edu.iff.projetoEstoque.repository;
import br.edu.iff.projetoEstoque.model.Entrada;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface EntradaRepository extends JpaRepository<Entrada, Long>{
public List<Entrada> findByFuncionariorespId(Long funcionariorespId, Pageable page);
}
package br.edu.iff.projetoEstoque;
//import br.edu.iff.projetoEstoque.model.Alocacao;
import br.edu.iff.projetoEstoque.model.Entrada;
import br.edu.iff.projetoEstoque.model.FuncionarioAdm;
import br.edu.iff.projetoEstoque.model.FuncionarioResp;
import br.edu.iff.projetoEstoque.model.Produto;
import br.edu.iff.projetoEstoque.repository.EntradaRepository;
import br.edu.iff.projetoEstoque.repository.FuncionarioAdmRepository;
import br.edu.iff.projetoEstoque.repository.FuncionarioRespRepository;
import br.edu.iff.projetoEstoque.repository.ProdutoRepository;
import java.util.Calendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProjetoEstoqueApplication implements CommandLineRunner{
@Autowired
private FuncionarioRespRepository funcionarioRespRepo;
@Autowired
private FuncionarioAdmRepository funcionarioAdmRepo;
@Autowired
private ProdutoRepository produtoRepo;
@Autowired
private EntradaRepository entradaRepo;
public static void main(String[] args) {
SpringApplication.run(ProjetoEstoqueApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
//FuncionarioResp
FuncionarioResp fr1 = new FuncionarioResp();
fr1.setNome("Ana");
fr1.setCpf("368.428.700-89");
fr1.setEmail("anacasdr@gmail.com");
fr1.setUsuario("anaca");
fr1.setSenha("060320");
funcionarioRespRepo.save(fr1);
//fr1.setDespaches();
//FuncionarioAdm
FuncionarioAdm fa1 = new FuncionarioAdm();
fa1.setNome("Hiwri");
fa1.setCpf("856.280.040-65");
fa1.setEmail("hiwri@gmail.com");
fa1.setUsuario("hiwri");
fa1.setSenha("330260");
fa1.setChave("2563569635");
funcionarioAdmRepo.save(fa1);
//Produto
Produto p1 = new Produto();
p1.setNome("Geladeira");
p1.setCategoria("Eletrodomestico");
p1.setPeso((int) 10.00);
produtoRepo.save(p1);
Entrada e1 = new Entrada();
e1.setFuncionarioresp((FuncionarioResp) List.of(fr1));
e1.setProduto((Produto) List.of(p1));
// e1.setAlocacao((Alocacao) List.of(a1));
e1.setDataHoraEntrada(Calendar.getInstance());
entradaRepo.save(e1);
}
}
<?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.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.edu.iff</groupId>
<artifactId>projetoEstoque</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projetoEstoque</name>
<description>Projeto para a disciplina de programação para WEB.</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>2.0.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.7.Final</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
作为一种解决方法,您可以禁用spring boot devtools autorestart。但是您需要禁用重启加载程序,所以在调用SpringApplication之前需要应用以下属性。跑您的主要方法如下所示:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApplication.class, args);
}
}
此外,如果您不需要devool,只需删除依赖项(spall-boot-devool)。
作为一个整体,我对Spring和Java非常陌生,目前正在开发一个API。我有一段代码,它访问MSSQL数据库,检索结果,并将其可视化,但它不起作用。我的意思是,如果我只调用过程并可视化结果集,它就会正常工作。问题是我无法处理“RatingProcedure”对象。当我尝试获取某个对象的值时,会显示以下错误: Hibernate:{调用dis_entity.spdcmpracovnici(?,,,
我是OSGi概念的新手,对于下面的错误,我非常感谢您的帮助。 当运行独立应用程序时没有问题,但是当同一个应用程序放在OSGI包中时,我们得到以下错误。 原因异常java.lang.运行时异常:无法实例化解析器org.apache.xerces.parsers.SAXParser:java.lang.类org.apache.xerces.parsers.SAXParser无法转换为类org.xml.
我们有一个更大的Spring启动应用程序,它会导致以下异常: 从IDEA IntelliJ与JPA类的关系开始。 从普通命令行启动时,应用程序运行良好。 在我们移除依赖之后 IDE内部的执行工作正常,没有任何问题。 我们正在使用: 创意智能2020.1.2 Spring Boot Version 2.3.1, JDK 11.0.7(采用开放式JDK), Apache Maven 3.6.3 有人已
我使用Wildfly 17,有两个无状态EJB,其中一个在JNDI查找时有时(但不总是)会导致问题。这是我的EJB: 当我部署我的应用程序时,我看到上面服务的以下日志: 我有一个ServiceLocator类,它是一个单例使用以下JNDI名称查找上述服务的存根: 现在,当我使用服务定位器获取服务存根时,我有时会得到下面的异常。但只是有时: 我在同一个war.模块中使用我的服务,在其中声明(相同的网
我想执行GET请求: 当我试图捕获我的HTTPResponse
问题内容: 目前,我正在处理一个包含子模块并使用numpy / scipy的python项目。Ipython用作交互式控制台。不幸的是,我对现在使用的工作流程不是很满意,请多多指教。 在IPython中,该框架是通过一个简单的命令加载的。但是,通常有必要在框架的子模块之一中更改代码。至此,一个模型已经加载完毕,我使用IPython与之交互。 现在,该框架包含许多相互依赖的模块,即,在最初加载框架时