我正在制作一个Spring Boot应用程序,用于从Oracle数据库获取数据并显示为字符串。这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
Http://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0
<groupId>com.mygit.boot</groupId>
<artifactId>sampleBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sampleBoot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<!-- HTTP Core -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
有人能帮个忙吗,拜托?ServerConfig是我的实体类,而我的控制器只是调用getAllConfigurationData()方法并将返回的列表打印为字符串。
package com.mygit.boot.dao.impl;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.mygit.boot.dao.IFetchDao;
import com.mygit.boot.entity.ServerConfig;
@Repository
@Transactional
public class FetchDaoImpl implements IFetchDao {
@PersistenceContext
private EntityManager entityManger;
@Override
public List<ServerConfig> getAllConfigurationData() {
try {
return entityManger.createQuery("select c from ServerConfig c", ServerConfig.class).getResultList();
} catch (Exception e) {
System.out.println("Exception while fetching server config !!!");
}
return null;
}
}
以下是我的错误:
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration.pageableCustomizer
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
控制器:
package com.mygit.boot.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mygit.boot.dao.IFetchDao;
import com.mygit.boot.entity.ServerConfig;
@RestController
public class TestController {
@Autowired
private IFetchDao fetchDao;
@RequestMapping("/test")
public String print() {
List<ServerConfig> l=fetchDao.getAllConfigurationData();
return l.toString();
}
}
实体类:com.mygit.boot.entity包;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;
@Entity
@Table(name = "serverconfig")
@NamedNativeQueries({ @NamedNativeQuery(name = "getMaxLoginAttemptsQuery", query = "SELECT * FROM serverconfig sconfig where sconfig.confKey=? and sconfig.configuration=?", resultClass = ServerConfig.class),
@NamedNativeQuery(name = "getPwdConfigProperties", query = "SELECT * FROM serverconfig sconfig WHERE sconfig.confKey IN ('"+Constants.NO_OF_UPPERCASES+"','"+Constants.NO_OF_LOWERCASES+"','"+Constants.NO_OF_DIGIT+"','"+Constants.NO_OF_SPECIALCHARS+"','"+Constants.PWD_MIN_LENGTH+"','"+Constants.PWD_MAX_LENGTH+"')", resultClass = ServerConfig.class)})
public class ServerConfig implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_SERVERCONFIG")
@SequenceGenerator(name = "SEQ_SERVERCONFIG", sequenceName = "SEQ_SERVERCONFIG")
private Long id;
@Column(name = "CONFIGURATION", length = 45)
private String configuration;
@Column(name = "CONFKEY", length = 128)
private String confKey;
@Column(name = "CONFVALUE", length = 4000)
private String confValue;
public ServerConfig() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getConfiguration() {
return configuration;
}
public void setConfiguration(String configuration) {
this.configuration = configuration;
}
public String getConfKey() {
return confKey;
}
public void setConfKey(String confKey) {
this.confKey = confKey;
}
public String getConfValue() {
return confValue;
}
public void setConfValue(String confValue) {
this.confValue = confValue;
}
}
主应用程序类:
package com.mygit.boot.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan({"com.mygit.boot.controller", "com.mygit.boot.dao", "com.mygit.boot.dao.impl", "com.mygit.boot.entity"})
public class SampleBootApplication {
public static void main(String[] args) {
SpringApplication.run(SampleBootApplication.class, args);
}
}
2条答案
按热度按时间cyej8jka1#
您可以尝试添加以下内容的正确版本吗
iqxoj9l92#
您能添加这个配置类吗?