我工作spring data,我创建一个配置类@Bean,@Entity以及Main.java但是跑项目时,我得到异常:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'todoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class entity.Todo
我的Main.java
public class Main {
@Autowired
private static TodoRepository todoRepository;
public static void main(String[] args) {
Todo todo = new Todo();
todo.setId(1l);
todo.setTitle("title");
System.out.println(todoRepository); //null
todoRepository.save(todo); //Exception in thread "main" java.lang.NullPointerException
}
}
Run Code Online (Sandbox Code Playgroud)
PersistenceContext.java
@Configuration
@EnableJpaRepositories(basePackages = {"repository"},
entityManagerFactoryRef = "entityManagerFactory",
transactionManagerRef = …Run Code Online (Sandbox Code Playgroud) 我有web-jpa项目,我的项目工作来自postgres和mysql数据库,但是当我在mysql db中添加新数据时,我得到异常:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not read a hi value - you need to populate the table: hibernate_sequence; nested exception is org.hibernate.id.IdentifierGenerationException: could not read a hi value - you need to populate the table: hibernate_sequence
ERROR [http-nio-8080-exec-5] <unknown>.<unknown> could not read a hi value - you need to populate the table: hibernate_sequence
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not read a hi value - you need …Run Code Online (Sandbox Code Playgroud) 我正在为我的项目尝试在tomcat 8中创建环境变量,我需要将此变量用于选择属性记录器.我读到setenv.sh并创建了这个文件,但是当我运行我的项目时 - 它没有运行.我如何创建环境变量来检查我的项目?我setenv在这个网站上读过.我使用的是ubuntu 14.04.
setenv.sh
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export JAVA_HOME
JAVA_OPTS="-Xmx4096m -Xms512m -server"
export JAVA_OPTS
CATALINA_HOME="/opt/tomcat"
export CATALINA_HOME
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用hibernate创建项目,但我在行中创建异常session factory,如果我删除此行 - 项目将运行成功.我搜索解决我读了这篇文章,并添加了依赖,hibernate-commons-annotations但这并没有解决问题
Caused by: java.lang.NoSuchMethodError: org.hibernate.annotations.common.reflection.java.JavaReflectionManager.injectClassLoaderDelegate(Lorg/hibernate/annotations/common/reflection/ClassLoaderDelegate;)V
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.generateDefaultReflectionManager(MetadataBuilderImpl.java:737)
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:709)
at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:127)
at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:655)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at com.secure.dao.impl.UserDaoImpl.<init>(UserDaoImpl.java:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
Run Code Online (Sandbox Code Playgroud)
线是:
at com.secure.dao.impl.UserDaoImpl.<init>(UserDaoImpl.java:20)
Run Code Online (Sandbox Code Playgroud)
等于代码中的行:
private SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Run Code Online (Sandbox Code Playgroud)
依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency> …Run Code Online (Sandbox Code Playgroud)