- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将一个小型应用程序从 TomCat 迁移到 WebLogic。当尝试部署到 weblogic 时,我收到标题中显示的错误。我查看了 SO 上的类似问题,并根据它们我更新了 mysql-connector 和 springboot 版本。作为引用,这是我用过的。 Return type of JPA Repository 'getOne(id)' Method java.math.BigInteger cannot be cast to java.lang.Integer
我将附上一些代码来帮助查明问题。
pom.xml
<?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>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.14.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<artifactId>timeoff</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>timeoff</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.1.RELEASE</version>
</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>
<version>8.0.18</version>
</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>
<exclusion>
<artifactId>tomcat-embed-el</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-core</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-websocket</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.1.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Dao.java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Controller;
@Controller
public interface EmployeeRequestDao extends JpaRepository <EmployeeRequest, Long> {
}
应用程序.java
@ComponentScan
@SpringBootApplication
public class TimeoffApplication extends SpringBootServletInitializer implements WebApplicationInitializer{
@Autowired
EmployeeRequestDao employeeRequestDao;
public static void main(String[] args) {
SpringApplication.run(TimeoffApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(TimeoffApplication.class);
}
}
EmployeeRequest.java
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "requestdetails")
public class EmployeeRequest {
@Id
@Column(name ="id")
@GeneratedValue(strategy =GenerationType.AUTO)
private Long id ;
public EmployeeRequest(String selectedSupervisor2, String selectedLeave2, String name, String fromDate, String fromTime, String toDate, String toTime) {
this.selectedSupervisor2 = selectedSupervisor2;
this.selectedLeave2 = selectedLeave2;
this.name = name;
this.fromDate = fromDate;
this.fromTime = fromTime;
this.toDate = toDate;
this.toTime = toTime;
}
public EmployeeRequest() {
}
@Column(name ="selectedSupervisor2")
private String selectedSupervisor2;
@Column(name ="selectedLeave2")
private String selectedLeave2;
@Column(name ="name")
private String name;
@Column(name ="fromDate")
private String fromDate;
@Column(name ="fromTime")
private String fromTime;
@Column(name ="toDate")
private String toDate;
@Column(name ="toTime")
private String toTime;
public String getSelectedSupervisor2() {
return selectedSupervisor2;
}
public void setSelectedSupervisor2(String selectedSupervisor2) {
this.selectedSupervisor2 = selectedSupervisor2;
}
public String getselectedLeave2() {
return selectedLeave2;
}
public void setselectedLeave2(String selectedLeave2) {
this.selectedLeave2 = selectedLeave2;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFromDate() {
return fromDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public String getFromTime() {
return fromTime;
}
public void setFromTime(String fromTime) {
this.fromTime = fromTime;
}
public String getToDate() {
return toDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
public String getToTime() {
return toTime;
}
public void setToTime(String toTime) {
this.toTime = toTime;
}
}
Controller .java
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import EmployeeRequest;
import EmployeeRequestDao;
@RestController
@RequestMapping("api")
@CrossOrigin(origins = "http://localhost:4200", allowedHeaders = "*")
public class EmployeeController {
@Autowired
EmployeeRequestDao employeeRequestDao;
/**
* This is used to get all requests in Employee leave
*
* @return
*/
@GetMapping("items")
public List<EmployeeRequest> getItems() {
return employeeRequestDao.findAll();
}
/**
* This method returns the requests by ID
*
* @param id
* @return
*/
@GetMapping("item/{id}")
public EmployeeRequest getItem(@PathVariable("id") Long id) {
return employeeRequestDao.getOne(id);
}
/**
* This method is used to add requests in the database
*
* @param employeeRequest
* @return
*/
@PostMapping("items")
public EmployeeRequest addItem(@RequestBody EmployeeRequest employeeRequest) {
return employeeRequestDao.save(employeeRequest);
}
/**
* This method is used to update requests.
*
* ??? Can potentially implement this further for supervisor access to approve
* or deny requests ???
*
* @param employeeRequest
* @return
*/
@PutMapping("item")
public EmployeeRequest saveOrUpdateItem(@RequestBody EmployeeRequest employeeRequest) {
return employeeRequestDao.save(employeeRequest);
}
/**
* This Method updates the requests by ID
*
* @param id
* @param employeeRequestDetails
* @return
*/
@PutMapping("item/{id}")
public EmployeeRequest updateItemById(@PathVariable Long id,
@Valid @RequestBody EmployeeRequest employeeRequestDetails) {
EmployeeRequest employeeRequest = employeeRequestDao.getOne(id);
employeeRequest.setName(employeeRequest.getName());
employeeRequest.setFromDate(employeeRequest.getFromDate());
employeeRequest.setFromTime(employeeRequest.getFromTime());
employeeRequest.setToDate(employeeRequest.getToDate());
employeeRequest.setToTime(employeeRequest.getToTime());
EmployeeRequest updatedItem = employeeRequestDao.save(employeeRequest);
return updatedItem;
}
/**
* This method is used to delete all requests from db.
*
* @param employeeRequest
*/
@DeleteMapping("items")
public void deleteAllItems(EmployeeRequest employeeRequest) {
employeeRequestDao.deleteAll();
}
/**
* This method deletes a request from db.
*
* @param id
* @return
*/
@DeleteMapping("items/{id}")
public String deleteItem(@PathVariable Long id) {
employeeRequestDao.delete(id);
return "Deleted";
}
/**
* This method patch updates the Date and Time of requests.
*
* @param partialUpdate
* @param id
* @return
*/
@PatchMapping("item/{id}")
public EmployeeRequest patchUpdateItemById(@PathVariable Long id, @Valid @RequestBody EmployeeRequest employeeRequestDetails) {
EmployeeRequest employeeRequest = employeeRequestDao.getOne(id);
employeeRequest.setFromDate(employeeRequestDetails.getFromDate());
employeeRequest.setFromTime(employeeRequestDetails.getFromDate());
EmployeeRequest updatedItem = employeeRequestDao.save(employeeRequest);
return updatedItem;
}
}
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import EmployeeRequest;
import EmployeeRequestDao;
@RestController
@RequestMapping("api")
@CrossOrigin(origins = "http://localhost:4200", allowedHeaders = "*")
public class EmployeeController {
@Autowired
EmployeeRequestDao employeeRequestDao;
/**
* This is used to get all requests in Employee leave
*
* @return
*/
@GetMapping("items")
public List<EmployeeRequest> getItems() {
return employeeRequestDao.findAll();
}
/**
* This method returns the requests by ID
*
* @param id
* @return
*/
@GetMapping("item/{id}")
public EmployeeRequest getItem(@PathVariable("id") Long id) {
return employeeRequestDao.getOne(id);
}
/**
* This method is used to add requests in the database
*
* @param employeeRequest
* @return
*/
@PostMapping("items")
public EmployeeRequest addItem(@RequestBody EmployeeRequest employeeRequest) {
return employeeRequestDao.save(employeeRequest);
}
/**
* This method is used to update requests.
*
* ??? Can potentially implement this further for supervisor access to approve
* or deny requests ???
*
* @param employeeRequest
* @return
*/
@PutMapping("item")
public EmployeeRequest saveOrUpdateItem(@RequestBody EmployeeRequest employeeRequest) {
return employeeRequestDao.save(employeeRequest);
}
/**
* This Method updates the requests by ID
*
* @param id
* @param employeeRequestDetails
* @return
*/
@PutMapping("item/{id}")
public EmployeeRequest updateItemById(@PathVariable Long id,
@Valid @RequestBody EmployeeRequest employeeRequestDetails) {
EmployeeRequest employeeRequest = employeeRequestDao.getOne(id);
employeeRequest.setName(employeeRequest.getName());
employeeRequest.setFromDate(employeeRequest.getFromDate());
employeeRequest.setFromTime(employeeRequest.getFromTime());
employeeRequest.setToDate(employeeRequest.getToDate());
employeeRequest.setToTime(employeeRequest.getToTime());
EmployeeRequest updatedItem = employeeRequestDao.save(employeeRequest);
return updatedItem;
}
/**
* This method is used to delete all requests from db.
*
* @param employeeRequest
*/
@DeleteMapping("items")
public void deleteAllItems(EmployeeRequest employeeRequest) {
employeeRequestDao.deleteAll();
}
/**
* This method deletes a request from db.
*
* @param id
* @return
*/
@DeleteMapping("items/{id}")
public String deleteItem(@PathVariable Long id) {
employeeRequestDao.delete(id);
return "Deleted";
}
/**
* This method patch updates the Date and Time of requests.
*
* @param partialUpdate
* @param id
* @return
*/
@PatchMapping("item/{id}")
public EmployeeRequest patchUpdateItemById(@PathVariable Long id, @Valid @RequestBody EmployeeRequest employeeRequestDetails) {
EmployeeRequest employeeRequest = employeeRequestDao.getOne(id);
employeeRequest.setFromDate(employeeRequestDetails.getFromDate());
employeeRequest.setFromTime(employeeRequestDetails.getFromDate());
EmployeeRequest updatedItem = employeeRequestDao.save(employeeRequest);
return updatedItem;
}
}
堆栈跟踪
```Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:336) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 104 common frames omitted
Caused by: java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1058) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:972) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:903) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1025) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3480) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2444) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:31) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at sun.reflect.GeneratedConstructorAccessor417.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_221]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_221]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:395) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:383) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) ~[tomcat-jdbc-8.5.31.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) ~[tomcat-jdbc-8.5.31.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 105 common frames omitted
Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:976) ~[mysql-connector-java-commercial-5.1.22-bin.jar:na]
... 128 common frames omitted
最佳答案
看起来问题发生在转换过程中。
所以您的 mysql 版本和 mysql-connector.jar 版本可能不匹配。您可以尝试使用更新版本的 MySQL Connector 吗?
我还发现您正在使用 mysql-connector-jar:8.0.18。但如果您看到堆栈跟踪,它会显示 mysql-connector-java-commercial-5.1.22-bin.jar。所以冲突的 jar 也可能是一个问题。
关于java - 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58881350/
这个问题在这里已经有了答案: Converting result of Math.sin(x) into a result for degrees in java (4 个答案) 关闭 5 年前。
我在学习 Kotlin 并在数学课上遇到了这个问题: java.lang.Math 和 kotlin.math 不兼容。这对我来说有点尴尬和困惑,因为 Kotlin 声称它与 Java 100% 兼容
我在其他问题中读到,例如由于浮点表示,sin(2π) 不为零,但非常接近。这个非常小的错误在我的代码中不是问题,因为例如我可以四舍五入 5 位小数。 但是当2π乘以一个非常大的数时,误差就会放大很多。
我正在用 C# 编写一个计算器。 textBoxResult 是我显示数字的文本框 recount 是一个以度为单位的角度并以弧度为单位返回的函数 我从 texBoxInput 获取角度 public
首先,让我们从我的数学背景开始。我已经学习了微积分 I - IV 和微分方程。我参加了第一学期的计算机图形类(class),在该类(class)中我们实现了几乎我们自己的图形管道,包括使用 Phong
早上好! 我只是想磨练我的数学能力,我特别有一些关于 Cocos2D 的问题。由于 Cocos2D 想要“简化”事物,所有 Sprite 都有一个旋转属性,范围从 0-360(359?)CW。这迫使你
是否有人对Intel Math Kernel Library和AMD Math Core Library都有编程经验?我正在建立一台用于高性能统计计算的个人计算机,并对正在购买的组件进行辩论。 AMD
函数的反函数是什么 math.atan2 我在 Lua 中使用它,我可以通过 math.tan 获得 math.atan 的逆。 但我在这里迷路了。 编辑 好的,让我向您提供更多详细信息。 我需要计算
我有一道等轴测投影的数学题。我读了一篇文章:Axonometric projections - a technical overview .对于等距投影部分,它给出了将 x 部分的 3D 点转换为 2
在 MySQL (5.1) 数据库表中,有数据表示: 用户执行任务需要多长时间 用户在任务中处理了多少项目。 MySQL 是否支持关联数据,还是我需要使用 PHP/C# 来计算? 我在哪里可以找到计算
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我正在尝试使用这两种方法在 C# 中解决这个问题: public double NormalPowerMethod(double x, double toPower) { return Mat
如何分配: var randomNumber = Math.random()*50 + Math.random()*20; 比较: var randomNumber = Math.random()*7
我正在查看我的代码,希望提高它的性能,然后我看到了这个: int sqrt = (int) Math.floor(Math.sqrt(n)); 哦,好的,我真的不需要调用 Math.floor,因为转
尝试调用 math.h 中的函数时, 我收到如下链接错误 undefined reference to sqrt 但我正在做一个 #include 我正在使用 gcc 并编译如下: gcc -Wall
祝大家有个愉快的一天,我有话要问你,为了更好地理解这里是我的代码: {math equation=((($order_total-$commission)+$discount+$delivery_ch
我尝试学习一些Clojure,因为该语言看起来不错。 但是似乎没有关于如何安装/使用库的信息,例如clojure.math.numeric-tower。 现在,我通过在Linux shell中键入以下
As Math.sign() 接受数字参数或数字作为字符串,如 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl
如何将scala.math.BigDecimal转换为java.math.BigDecimal? 最佳答案 无需在字符串之间进行双重转换。 val sb = scala.math.BigDecimal
为什么下面的 JavaScript 会这样 Math instanceof Math 抛出错误 TypeError: Expecting a function in instanceof check,
我是一名优秀的程序员,十分优秀!