这是我的spring-ws-servlet.xml
<beans xmlns="http://www.springframeworkI.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
">
<context:component-scan base-package="com.symbio.points"/>
<!-- endpoint终端扫描 -->
<sws:annotation-driven/>
<sws:static-wsdl location="/WEB-INF/wsdl/MembershipService.wsdl"/>
这是我的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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties" />
<!-- 自动扫描dao和service包(自动注入) -->
<context:annotation-config />
<!-- 配置数据源 c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 请求超时时间 -->
<property name="checkoutTimeout" value="30000" />
<!-- 每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 -->
<property name="idleConnectionTestPeriod" value="30" />
<!-- 连接数据库连接池最大空闲时间 -->
<property name="maxIdleTime" value="30" />
<!-- 连接池初始化连接数 -->
<property name="initialPoolSize" value="5" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 -->
<property name="acquireIncrement" value="5" />
</bean>
<!-- 配置hibernate的SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 注入数据源 相关信息看源码 -->
<property name="dataSource" ref="dataSource" />
<!-- hibernate配置信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<!-- <prop key="current_session_context_class">thread</prop> -->
</props>
</property>
<!-- 扫描hibernate注解配置的entity -->
<property name="packagesToScan" value="com.symbio.points.membership" />
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 注解方式配置事物 -->
<!--<tx:annotation-driven transaction-manager="transactionManager"/> -->
<!-- 拦截器配置事务-->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<!-- 配置详细事务处理语义 -->
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="select*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<!-- 其他采用默认事务方式 -->
<tx:method name="*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<!-- Spring aop事务管理 -->
<aop:config>
<!-- 配置切入点 -->
<aop:pointcut id="transactionPointcut" expression="execution(* com.symbio.points.service.*.*(..))" />
<!-- 指定在txAdvice切入点应用txAdvice事务增强处理 -->
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>points-manage</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>opensessioninview</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>opensessioninview</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<!-- Spring WS配置文件的位置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/points-servlet.xml</param-value>
</init-param>
<!-- 设置transformWsdlLocations为true的话,及时改变了项目名称或端口号,服务还可以正常访问 -->
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>*.wsdl</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- log4j2 -->
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
</web-app>
MembershipServiceImpl.java
package com.symbio.points.service.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.symbio.points.membership.Membership;
import com.symbio.points.repository.IMembershipDao;
import com.symbio.points.repository.impl.PointsAccountDaoImpl;
import com.symbio.points.service.IMembershipService;
@Service
@Transactional
public class MembershipServiceImpl implements IMembershipService {
@Resource
private IMembershipDao membershipDao;
@Resource
private PointsAccountDaoImpl pointsAccountDao;
// when a membership was created, then the related pointsAccount has to be created
@Transactional
public String addMember(Membership membership) {
String info = membershipDao.addMember(membership);
return info;
}
@Transactional
public String updateMember(Membership membership) {
String updateInfo = membershipDao.updateMember(membership);
return updateInfo;
}
@Transactional
public void deleteMember(Integer id) {
membershipDao.deleteMember(id);
}
}
MembershipDaoImpl.java
@Repository("membershipDao")
public class MembershipDaoImpl implements IMembershipDao {
@Autowired
private SessionFactory sessionFactory;
public Session getSession() {
Session session = sessionFactory.getCurrentSession();
return session;
}
public String addMember(Membership membership) {
this.getSession().save(membership);
return "insert success";
}
public Membership loadMember(Integer id) {
return this.getSession().load(Membership.class, id);
}
public void deleteMember(Integer id) {
Membership member = this.loadMember(id);
this.getSession().delete(member);
}
public String updateMember(Membership membership) {
this.getSession().saveOrUpdate(membership);
return "update success";
}
public List<Membership> findAllMember() {
return this.getSession().createQuery("fromMembership").list();
}
// get by id
public Membership findMemberById(Integer id) {
return this.getSession().get(Membership.class, id);
}
}
记录插入
15:24:18.571 TRACE org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl 1217 openSession - Opening Hibernate Session. tenant=null, owner=null
15:24:18.645 TRACE org.hibernate.service.internal.AbstractServiceRegistryImpl 229 initializeService - Initializing service [role=org.hibernate.stat.spi.StatisticsImplementor]
15:24:18.649 DEBUG org.hibernate.stat.internal.StatisticsInitiator 82 initiateServiceInternal - Statistics initialized [enabled=false]
15:24:18.655 TRACE org.hibernate.internal.SessionImpl 286 <init> - Opened Session [6e299939-2e1b-4843-88b1-633245af25ad] at timestamp: 15235178586
15:24:18.721 TRACE org.hibernate.event.internal.DefaultSaveOrUpdateEventListener 163 entityIsTransient - Saving transient instance
15:24:18.725 TRACE org.hibernate.event.internal.AbstractSaveEventListener 157 performSave - Saving [com.symbio.points.membership.Membership#<null>]
15:24:18.734 TRACE org.hibernate.engine.spi.ActionQueue 305 addAction - Adding an EntityIdentityInsertAction for [com.symbio.points.membership.Membership] object
15:24:18.734 TRACE org.hibernate.engine.spi.ActionQueue 255 addInsertAction - Executing inserts before finding non-nullable transient entities for early insert: [EntityIdentityInsertAction[com.symbio.points.membership.Membership#<null>]]
15:24:18.737 TRACE org.hibernate.engine.spi.ActionQueue 260 addInsertAction - Adding insert with no non-nullable, transient entities: [EntityIdentityInsertAction[com.symbio.points.membership.Membership#<null>]]
15:24:18.737 TRACE org.hibernate.engine.spi.ActionQueue 277 addResolvedEntityInsertAction - Executing insertions before resolved early-insert
15:24:18.737 DEBUG org.hibernate.engine.spi.ActionQueue 279 addResolvedEntityInsertAction - Executing identity-insert immediately
15:24:18.738 TRACE org.hibernate.persister.entity.AbstractEntityPersister 2903 insert - Inserting entity: com.symbio.points.membership.Membership (native id)
15:24:18.740 DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger 92 logStatement - insert into membership (ADDRESS, CELL_PHONE, CREATED_BY_ID, CREATED_DTTM, EMAIL, ENTERPRISE_CD, EXTERNAL_MEMBERSHIP_ID, FIRST_NAME, INITIAL_DTTM, LAST_NAME, LAST_UPDATED_BY_ID, LAST_UPDATED_DTTM, MEMBER_TYPE_ID, MEMBERSHIP_NUM, PRODUCT_LINE_ID, SOURCE_COMPANY_ID, STATUS_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into membership (ADDRESS, CELL_PHONE, CREATED_BY_ID, CREATED_DTTM, EMAIL, ENTERPRISE_CD, EXTERNAL_MEMBERSHIP_ID, FIRST_NAME, INITIAL_DTTM, LAST_NAME, LAST_UPDATED_BY_ID, LAST_UPDATED_DTTM, MEMBER_TYPE_ID, MEMBERSHIP_NUM, PRODUCT_LINE_ID, SOURCE_COMPANY_ID, STATUS_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
15:24:18.753 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 66 register - Registering statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@1f75d051]
15:24:18.754 TRACE org.hibernate.persister.entity.AbstractEntityPersister 2709 dehydrate - Dehydrating entity: [com.symbio.points.membership.Membership#<null>]
15:24:18.756 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [1] as [VARCHAR] - [we]
15:24:18.757 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [2] as [VARCHAR] - [12345]
15:24:18.757 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [3] as [VARCHAR] - [Pirce]
15:24:18.758 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [4] as [TIMESTAMP] - [Wed Dec 12 00:00:00 CST 2018]
15:24:18.759 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [5] as [VARCHAR] - [hello@123.com]
15:24:18.759 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [6] as [VARCHAR] - [123]
15:24:18.760 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [7] as [VARCHAR] - [123]
15:24:18.760 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [8] as [VARCHAR] - [whoever]
15:24:18.761 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [9] as [TIMESTAMP] - [Wed Oct 10 00:00:00 CST 2018]
15:24:18.761 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [10] as [VARCHAR] - [Elena]
15:24:18.761 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [11] as [VARCHAR] - [Katherine]
15:24:18.761 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [12] as [TIMESTAMP] - [Fri Dec 13 00:00:00 CST 1017]
15:24:18.762 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [13] as [INTEGER] - [123]
15:24:18.762 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [14] as [VARCHAR] - [12222]
15:24:18.763 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [15] as [INTEGER] - [123]
15:24:18.763 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [16] as [INTEGER] - [123]
15:24:18.763 TRACE org.hibernate.type.descriptor.sql.BasicBinder 65 bind - binding parameter [17] as [INTEGER] - [22]
15:24:18.832 DEBUG org.hibernate.id.IdentifierGeneratorHelper 78 getGeneratedIdentity - Natively generated identity: 26
15:24:18.833 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 102 release - Releasing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@7f560073]
15:24:18.834 DEBUG org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 115 release - HHH000387: ResultSet's statement was not registered
15:24:18.835 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 143 close - Closing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@7f560073]
15:24:18.837 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 79 release - Releasing statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@1f75d051]
15:24:18.838 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 159 close - Closing prepared statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@1f75d051]
15:24:18.839 TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl 269 afterStatementExecution - Starting after statement execution processing [ON_CLOSE]
15:24:18.864 TRACE org.hibernate.internal.SessionImpl 406 close - Closing session [6e299939-2e1b-4843-88b1-633245af25ad]
15:24:18.865 TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl 179 close - Closing JDBC container [org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl@14aa4336]
15:24:18.866 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 297 releaseResources - Releasing JDBC resources
15:24:18.867 TRACE org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl 237 close - Closing logical connection
15:24:18.868 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 297 releaseResources - Releasing JDBC resources
15:24:18.869 TRACE org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl 244 close - Logical connection closed
更新日志(不会在db中更新)
15:33:04.064 TRACE org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl 1217 openSession - Opening Hibernate Session. tenant=null, owner=null
15:33:04.065 TRACE org.hibernate.internal.SessionImpl 286 <init> - Opened Session [fdf69b28-065d-4a4a-b27c-85d3c6a43be2] at timestamp: 15235183840
15:33:04.105 TRACE org.hibernate.engine.spi.IdentifierValue 130 isUnsaved - ID unsaved-value: null
15:33:04.106 TRACE org.hibernate.event.internal.AbstractSaveEventListener 506 getEntityState - Detached instance of: com.symbio.points.membership.Membership
15:33:04.120 TRACE org.hibernate.event.internal.DefaultSaveOrUpdateEventListener 210 entityIsDetached - Updating detached instance
15:33:04.121 TRACE org.hibernate.event.internal.DefaultSaveOrUpdateEventListener 275 performUpdate - Updating [com.symbio.points.membership.Membership#1]
15:33:04.128 TRACE org.hibernate.event.internal.DefaultSaveOrUpdateEventListener 322 performUpdate - Updating [com.symbio.points.membership.Membership#1]
15:33:04.135 TRACE org.hibernate.internal.SessionImpl 406 close - Closing session [fdf69b28-065d-4a4a-b27c-85d3c6a43be2]
15:33:04.136 TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl 179 close - Closing JDBC container [org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl@1b482c22]
15:33:04.136 TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl 297 releaseResources - Releasing JDBC resources
15:33:04.136 TRACE org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl 237 close - Closing logical connection
15:33:04.136 TRACE org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl 244 close - Logical connection closed
会员实体
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "membership", propOrder = {
"membershipId",
"initialDate",
"membershipNum",
"statusId",
"lastUpdateDate",
"lastUpdateBy",
"createdDate",
"createdBy",
"enterpriseCD",
"productLineId",
"externalMembershipId",
"memberTypeId",
"sourceCompanyId",
"lastName",
"firstName",
"email",
"address",
"cellphone"
})
@Entity
@Table(name="membership")
public class Membership implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8971217797523883077L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="MEMBERSHIP_ID", unique=true, nullable=false)
@XmlElement(required = true)
protected Integer membershipId;
@Column(name="INITIAL_DTTM", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
@XmlElement(required = true)
@XmlSchemaType(name = "date")
protected Date initialDate;
@XmlElement(required = true)
@Column(name="MEMBERSHIP_NUM", nullable=false, length=32)
protected String membershipNum;
@Column(name="STATUS_ID", nullable=false)
@XmlElement(required = true)
protected Integer statusId;
@Column(name="LAST_UPDATED_DTTM", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
@XmlElement(required = true)
@XmlSchemaType(name = "date")
protected Date lastUpdateDate;
@Column(name="LAST_UPDATED_BY_ID", nullable=false)
@XmlElement(required = true)
protected String lastUpdateBy;
@Column(name="CREATED_DTTM", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
@XmlElement(required = true)
@XmlSchemaType(name = "date")
protected Date createdDate;
@Column(name="CREATED_BY_ID", nullable=false)
@XmlElement(required = true)
protected String createdBy;
@Column(name="ENTERPRISE_CD", nullable=false)
@XmlElement(required = true)
protected String enterpriseCD;
@Column(name="PRODUCT_LINE_ID", nullable=false)
protected Integer productLineId;
@XmlElement(required = true)
@Column(name="EXTERNAL_MEMBERSHIP_ID", nullable=false)
protected String externalMembershipId;
@Column(name="MEMBER_TYPE_ID", nullable=false)
protected int memberTypeId;
@Column(name="SOURCE_COMPANY_ID", nullable=false)
protected int sourceCompanyId;
@Column(name="LAST_NAME", nullable=false)
@XmlElement(required = true)
protected String lastName;
@Column(name="FIRST_NAME", nullable=false)
@XmlElement(required = true)
protected String firstName;
@Column(name="EMAIL", nullable=false)
@XmlElement(required = true)
protected String email;
@Column(name="ADDRESS", nullable=false)
@XmlElement(required = true)
protected String address;
@Column(name="CELL_PHONE", nullable=false)
@XmlElement(required = true)
protected String cellphone;
有人请帮助我!我尝试了很多方法,但它仍然无效。 谢谢!