我刚开始使用Spring靴。我试图用apache derby创建一个REST API,将其作为嵌入式数据库,但我得到了以下错误:
<groupId>com.restapi</groupId>
<artifactId>restApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>restApi</name>
<description>Demo project for Rest API with spring boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.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-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.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
@RequestMapping(value="/topics")
public List<Topic> getTopics(){
return topicService.getAllTopics();
}
@RequestMapping(value="/topics",method=RequestMethod.POST)
public void addTopic(@RequestBody Topic topic){
topicService.addTopic(topic);
}
商业服务:
public List<Topic> getAllTopics(){
List<Topic> topics = new ArrayList();
topicRepository.findAll().forEach(topics::add);
return topics;
}
public void addTopic(Topic topic){
topicRepository.save(topic);
}
实体类存储库:
public interface TopicRepository extends CrudRepository<Topic, Long>{
}
@Entity
public class Topic {
@Id
@GeneratedValue
private Long id;
private String name;
private String description;
public Topic(){
}
public Topic(Long id, String name, String description) {
super();
this.id = id;
this.name = name;
this.description = description;
}
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 getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@SpringBootApplication
public class RestApiApplication {
public static void main(String[] args) {
SpringApplication.run(RestApiApplication.class, args);
}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.2.RELEASE)
2017-04-05 20:11:15.788 INFO 8756 --- [ main] com.restapi.RestApiApplicationTests : Starting RestApiApplicationTests on DESKTOP-8C6TQN1 with PID 8756 (started by mahid in C:\Users\mahid\Documents\NetBeansProjects\restApi)
2017-04-05 20:11:15.788 INFO 8756 --- [ main] com.restapi.RestApiApplicationTests : No active profile set, falling back to default profiles: default
2017-04-05 20:11:15.865 INFO 8756 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@702b8b12: startup date [Wed Apr 05 20:11:15 CDT 2017]; root of context hierarchy
2017-04-05 20:11:17.915 INFO 8756 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c3650505] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-04-05 20:11:19.282 INFO 8756 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-04-05 20:11:19.315 INFO 8756 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-04-05 20:11:19.432 INFO 8756 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-04-05 20:11:19.435 INFO 8756 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-04-05 20:11:19.439 INFO 8756 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-04-05 20:11:19.506 INFO 8756 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-04-05 20:11:19.777 INFO 8756 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
2017-04-05 20:11:19.784 WARN 8756 --- [ main] org.hibernate.dialect.DerbyDialect : HHH000430: The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead
2017-04-05 20:11:20.476 WARN 8756 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2017-04-05 20:11:20.491 INFO 8756 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-04-05 20:11:20.491 ERROR 8756 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
我没有在application.properties中定义任何内容。
这个异常清楚地告诉您,您同时混合了hibernate库和JPA库。因为跨库导入和尝试运行应用程序给了您异常。您正在尝试根据exception创建Hibernate SessionFactory,并且您可能正在为其他。确保您正在导入所有JPA库或所有hibernate库。不应该交叉导入库。请检查您的代码并确保。
“org.springframework.beans.factory.beanCreationException:创建类路径资源[org/springframework/boot/autocconfigure/orm/jpa/hibernatejpaAutocconfiguration.class]中定义的名为'Entity ManagerFactory'的bean时出错:html" target="_blank">调用init方法失败;嵌套异常为javax.persistence.persistenceException:[persistenceUnit:default]无法在
或者是我错过了一些文档(Spring,Spring Boot,H2,HSQLDB,Derby,IntelliJ)中的一些核心概念,或者是我已经关注这个问题太久了。 我有一个春靴项目要做。最初尝试使用并初始化一个H2数据库,尝试在IntelliJ中连接到它,只是意识到如果不放弃我的第一个孩子(使用IntelliJ数据库客户端连接到H2数据库),我可能无法轻松地浏览数据库。 所以我搬到了Derbydb
我在Spring Batch上有点麻烦。我正处于这种情况:我必须分析文件中的数据,并将所有内容插入数据库(Oracle)。我面临的问题是,当我试图配置用于保存数据的数据库时,应用程序崩溃并关闭。我有一条错误消息: Application.Properties 用于配置数据库的MultipleDBConfig.java Bean
我有一个Spring Boot和嵌入式Mongo DB的项目,我也想查找存储在那里的数据。我学习了本教程https://springframework.guru/spring-boot-with-embedd-mongoDB/
我有一个spring项目,我正在设置一个用于测试的嵌入式数据库(目前是HSQLDB)。我已经设置了自定义上下文和数据源,以使用脚本文件初始化应用程序。当我对项目运行mvn(版本2)时,所有的构建和测试都很好,但一旦切换到mvn(版本3),每当嵌入式数据库有标记时,我就会收到一个错误。我可以删除标记,并且我有一个可以运行命令的工作数据源,但是添加单个脚本文件(即使是空的)每次都会失败。 我知道文件存
请在此查看结构。
问题内容: 术语“嵌入式数据库”与“数据库”具有不同的含义吗? 问题答案: 我已经看到了嵌入式数据库的两个定义: 嵌入式数据库,例如专门为“嵌入式”空间(移动设备等)设计的数据库系统。这意味着它们在紧凑的环境中(在内存/ CPU方面)表现合理。 嵌入式数据库,就像不需要服务器的数据库一样,并且嵌入在应用程序中(例如SQLite)。这意味着所有内容都由应用程序管理。 我个人从未见过该术语完全按照Wi