应用Context.ml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>it.davidefruci.casadiscografica2.beans.Album</value>
<value>it.davidefruci.casadiscografica2.beans.Artist</value>
<value>it.davidefruci.casadiscografica2.beans.Song</value>
<value>it.davidefruci.casadiscografica2.beans.RecordCompany</value>
<value>it.davidefruci.casadiscografica2.beans.Category</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- DAO -->
<bean id="albumDao" class="it.davidefruci.casadiscografica2.daoImpl.AlbumDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="artistDao" class="it.davidefruci.casadiscografica2.daoImpl.ArtistDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="categoryDao" class="it.davidefruci.casadiscografica2.daoImpl.CategoryDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="recordCompanyDao" class="it.davidefruci.casadiscografica2.daoImpl.RecordCompanyDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="songDao" class="it.davidefruci.casadiscografica2.daoImpl.SongDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- BO -->
<bean id="albumBo" class="it.davidefruci.casadiscografica2.boImpl.AlbumBoImpl">
<property name="albumDao" ref="albumDao"></property>
</bean>
<bean id="artistBo" class="it.davidefruci.casadiscografica2.boImpl.ArtistBoImpl">
<property name="artistDao" ref="artistDao"></property>
</bean>
<bean id="categoryBo" class="it.davidefruci.casadiscografica2.boImpl.CategoryBoImpl">
<property name="categoryDao" ref="categoryDao"></property>
</bean>
<bean id="recordCompanyBo" class="it.davidefruci.casadiscografica2.boImpl.RecordCompanyBoImpl">
<property name="recordCompanyDao" ref="recordCompanyDao"></property>
</bean>
<bean id="songBo" class="it.davidefruci.casadiscografica2.boImpl.SongBoImpl">
<property name="songDao" ref="songDao"></property>
</bean>
包it.davidefruci.casadiscografica2.dao
public interface AlbumDao {
public void save(Album album) throws Exception;
public void delete(int id) throws Exception;
public void update(Album album) throws Exception;
public Album findById(int id) throws Exception;
public Album findByName(String name) throws Exception;
public List<Album> getAllAlbum() throws Exception;
}
把它打包。davidefruci。卡萨迪斯科格拉菲卡2。daoImpl;
public class AlbumDaoImpl implements AlbumDao {
@Autowired
@Qualifier("sessionFactory")
SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory factory) {
this.sessionFactory = factory;
}
@Override
public void save(Album album) throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(album);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
} else {
e.printStackTrace();
}
} finally {
session.close();
}
}
@Override
public void delete(int id) throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Album album = (Album) session.get(Album.class, id);
session.delete(album);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
} else {
e.printStackTrace();
}
} finally {
session.close();
}
}
@Override
public void update(Album album) throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(album);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
}
@Override
public Album findById(int id) throws Exception {
Session session = sessionFactory.openSession();
Album album = null;
try {
album = (Album) session.get(Album.class, id);
} catch (HibernateException e) {
throw e;
} finally {
session.close();
}
return album;
}
@Override
public Album findByName(String name) throws Exception {
Session session = sessionFactory.openSession();
Album album = null;
List<Album> list = new ArrayList<Album>();
try {
Query query = session.createQuery("FROM Album WHERE name= :name");
query.setParameter("name", name);
list = query.list();
if (list != null) {
if (list.size() == 1) {
album = list.get(0);
}
}
} catch (HibernateException e) {
throw e;
} finally {
session.close();
}
return album;
}
@Override
public List<Album> getAllAlbum() throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
List<Album> list = null;
try {
list = session.createQuery("FROM Album").list();
} catch (HibernateException e) {
throw e;
} finally {
session.close();
}
return list;
}
}
Tomcat没有部署应用程序。上面说
FAIL-在上下文路径 /CasaDiscografica2部署应用程序,但上下文无法启动
给我一个错误:
组织。springframework。豆。工厂BeanCreationException:创建名为“albumDao”的bean时出错,该bean在ServletContext资源[/WEB-INF/applicationContext.xml]中定义:设置属性值时出错;嵌套的异常是org。springframework。豆。NotWritablePropertyException:bean类的属性“sessionFactory”无效
和
组织。springframework。豆。NotWritablePropertyException:bean类[it.davidefruci.casadiscografica2.daoImpl.AlbumDaoImpl]的无效属性“sessionFactory”:bean属性“sessionFactory”不可写或具有无效的setter方法。setter的参数类型与getter的返回类型匹配吗?
为什么?谢谢
有人知道如何获得由Spring Boot创建的Hibernate SessionFactory的句柄吗?
我试图上传一个图像到内存使用multer,然后处理它与夏普和保存到磁盘。当我尝试在我的中间件中做多个module.exports时。 错误是: TypeError FileUpload.Single不是函数 到目前为止的路线是: 当我刚刚有下面的路由之前,尝试添加图像处理,我没有得到一个错误;
问题内容: 两个问题 1)将Java项目导出为JAR文件时,应用程序如何知道包中的哪个类首先运行?我的applicatino特别要求userInterface.java文件在CommonDenom.java文件之前运行。 2)运行Java文件时,出现错误消息“无法启动Java JAR文件“ commonDenom.jar”。请在控制台中查看可能的消息。” 我从哪里开始弄清楚这一点?我检查了控制台,
我尽了最大努力,但没有成功。< code >索引操作加载正常,但当我导航到test时,生成了错误。不知道为什么会这样。 磅.xml struts.xml 平铺.xml 错误 项目结构
我正试图向我的服务器提交用户名和手机的设备ID,但我不断得到以下错误: w/system.err:soapfault-faultcode:“soap:client”faultstring:“unmarshalling错误:意外元素(URI:”http://eventmanagement.management.de/“,local:”username“)。需要的元素是<{}deviceid>、<{}
问题内容: 我正在使用Python编写一些加密算法,但是我以前从未使用过Python。 首先,看一下这段代码,然后我将解释这个问题, x和y的值为, 我不明白代码的第三行。为了理解第三行,我不得不研究函数,我遇到了这个问题, zip函数帮助元组 根据这个问题的答案,代码, 将输出, 但是当我尝试打印时, 我得到这个输出, 为什么我的输出与原始输出不同? 问题答案: 在Python 3中返回一个迭代
您好,我在react js中有此组件: 我需要导出返回函数中的这一行:作为变量在另一个组件中使用它。 所以我这样做了: 但是我得到了这个错误:意外的令牌,预期的,(47:20) 有人能帮我导出变量吗
我有一个JProfiler快照文件(.jps),它是使用脱机分析创建的。 当我试图使用JPexport脚本导出它时,出现以下错误: /opt/jprofiler9/bin$jpexport ~/test。jps热点~/热点。html加载/home/pavan/test。jps JProfiler尚未初始化。请先运行JProfiler可执行文件 请任何人详细说明这意味着什么,以及需要做什么才能成功地