- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在这里尝试集成 Spring Hibernate。这是我正在尝试运行的简单示例。我在运行时遇到错误]请帮忙。
EmployeeDAO.java
package com.spring.hibernate.dao;
import com.spring.hibernate.bean.EmployeeBean;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class EmployeeDAO {
HibernateTemplate template;
public void setTemplate(HibernateTemplate template) {
this.template = template;
}
public void saveEmployee(EmployeeBean e){
template.save(e);
}
public void deleteEmployee(EmployeeBean e){
template.delete(e);
}
public void updateEmployee(EmployeeBean e){
template.update(e);
}
}
EmployeeBean.java
package com.spring.hibernate.bean;
public class EmployeeBean {
private int emp_id,emp_age;
public int getEmp_id() {
return emp_id;
}
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}
public int getEmp_age() {
return emp_age;
}
public void setEmp_age(int emp_age) {
this.emp_age = emp_age;
}
public String getEmp_name() {
return emp_name;
}
public void setEmp_name(String emp_name) {
this.emp_name = emp_name;
}
public String getEmp_address() {
return emp_address;
}
public void setEmp_address(String emp_address) {
this.emp_address = emp_address;
}
public float getEmp_salary() {
return emp_salary;
}
public void setEmp_salary(float emp_salary) {
this.emp_salary = emp_salary;
}
private String emp_name, emp_address;
private float emp_salary;
}
SpringHibernateConsoole.java
package spring.hibernate.console;
import com.spring.hibernate.bean.EmployeeBean;
import com.spring.hibernate.dao.EmployeeDAO;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class SpringHibernateConsole {
public static void main(String[] args) {
Resource res = new ClassPathResource("applicationContext.xml");
BeanFactory beanFactory = new XmlBeanFactory(res);
EmployeeDAO dao = (EmployeeDAO)beanFactory.getBean("d");
EmployeeBean emp = new EmployeeBean();
emp.setEmp_id(23);
emp.setEmp_name("amit");
emp.setEmp_salary(15224);
emp.setEmp_address("Ramakrishrna apratment new delhi");
dao.saveEmployee(emp);
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="dirverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=BFPL;instanceName=SQLEXPRESS;"></property>
<property name="username" value="appuser" ></property>
<property name="password" value="commando"></property>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"></property>
<property name="mappingResources">
<list>
<value>employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="myTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<bean id="d" class="com.spring.hibernate.dao.EmployeeDAO">
<property name="template" ref="myTemplate"></property>
</bean>
</beans>
employee.hbm
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.spring.hibernate.bean.EmployeeBean">
<id name="emp_id">
<generator class="assigned"></generator>
</id>
<property name="emp_name"></property>
<property name="emp_salary"></property>
<property name="emp_address"></property>
<property name="emp_age"></property>
</class>
</hibernate-mapping>
error : (Updated)
run:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'myTemplate' while setting bean property 'template'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:326)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at spring.hibernate.console.SpringHibernateConsole.main(SpringHibernateConsole.java:19)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:326)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
... 10 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
... 20 more
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:269)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:863)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:782)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 27 more
Java Result: 1
BUILD SUCCESSFUL (total time: 8 seconds)
最佳答案
看起来您的应用程序中缺少一些 hibernate 依赖项。不过,我建议您将 hibernate 属性保留在 hibernate.cfg.xml 文件中,而不是放在 application-context.xml 中。如果它能解决您的问题。
关于java - 我在设置 spring hibernate application-context.xml 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585341/
我正在尝试加载外部 SVG 并将其附加到 Electron 项目中的现有 SVG。 d3.xml 方法对我不起作用,所以我正在查看 d3.symbols ,希望如果我提供路径数据(来自 fs.read
我正在编写一个 Web 应用程序,使用 Go 作为后端。我正在使用这个 GraphQL 库 (link)和 Echo Web 框架 (link) .问题在于 graphql-go 库在 Go 中使用了
有没有办法改造 gin.Context至 context.Context在围棋?构建 Go 微服务应该使用什么? 最佳答案 标准库的 context.Context type 是一个接口(interf
如果我能够像这样注册一个接收器: LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new Inte
如果我有 appengine.Context 而不是 ,我不知道如何调用 cloud.WithContext 和 google.DefaultClient >上下文。上下文。 有(旧的)“appeng
有什么区别- AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SER
我刚读了这篇文章:Build You Own Web Framework In Go为了在处理程序之间共享值,我选择了 context.Context我通过以下方式使用它在处理程序和中间件之间共享值:
在 Visual Studio Code 中,我对 3 个“上下文”菜单项感到非常困惑:Run Tests in Context和 Debug Tests in Context和 Run .NET C
我正在使用带有 和 @Autowired 的 Spring 2.5.6 版本。 虽然我在调度程序上下文中使用 SimpleUrlHandlerMapping ,但一切正常 - Autowiring 工
我使用的是 Context.registerReceiver()、Context.sendBroadcast(Intent) 和 Context.unregisterReceiver() 但是当我看到
问题在于以下错误, [错误] 在 scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580)[错误] 在 scal
最近我正在尝试使用 SoundPool 在我的应用程序中播放一些简单的音效 但不幸的是它在 AVD 中不起作用并且应用程序崩溃 “上下文”到底是什么意思? 完全不懂 提前致谢 最佳答案 任何上下文都允
我正在使用上下文建议器,我想知道我们是否可以设置用于建议的上下文范围,而不是使用所有上下文。 目前查询需要匹配所有上下文。我们能否在上下文中添加“或”运算和/或指定用于特定查询的上下文? 以here为
我被一个使用这种方法的函数卡住了。所以我知道如何使用 expressionValue(with:context:) 函数,但上下文如何参与对我来说仍然是不透明的。也许有人有简单的例子? try tra
我正在尝试在上下文管理器中更改我的 python 程序中的目录。使用 invoke.context.Context 似乎是正确的方法,从 Fabric 文档中获取并且使用常规 with os.chdi
我最近开始使用 Android Studio 处理我的 Android 项目。我注意到在 IDE 的右下角,有文本 Context: .好奇心打败了我,所以现在我正在网上搜索更多信息。我还没有找到任
假设我有这些功能: func A(ctx context.Context) { // A takes some time to process } func B(ctx context.Con
所以,我有一个 context.Context( https://golang.org/pkg/context/ ) 变量,有没有办法列出这个变量包含的所有键? 最佳答案 可以使用不安全反射列出 co
我正在尝试找出传播 context.Context 的正确方法用于在使用 Gin 时使用 OpenTelemetry 进行跟踪。 我目前有一个 gin调用函数并传递 *gin.Context 的处理程
我们可以使用 Remove["context`*"] 删除特定上下文中的所有符号。 .但是是否可以删除 "context`"自己从系统中删除,以便它不再在 Contexts[] 中列出? 最佳答案 据
我是一名优秀的程序员,十分优秀!