Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
是因为Service中的方法与事务策略中定义的方法名不匹配 ,spring将使用默认的事务传播和只读属性(REQUIRED,readOnly)。
解决办法:在web.xml中配置
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
或 在使用方法前将flushmode设置成Auto或Commit
eg: Session session = getSessionFactory().openSession();
session.setFlushMode(FlushMode.AUTO);
session.save(obj);
session.flush();
就能解决了,good lucky!