我有一个MySQL数据库,我尝试配置一个Spring应用程序来访问它。我从模板创建了一个新的JPA Spring项目。
我修改了persistence.xml,现在它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="application" transaction-type="RESOURCE_LOCAL">
<class>com.windy.spring.FavoriteSport</class>
<class>com.windy.spring.FavoriteSpot</class>
<class>com.windy.spring.FavoriteUser</class>
<class>com.windy.spring.Role</class>
<class>com.windy.spring.Sport</class>
<class>com.windy.spring.Spot</class>
<class>com.windy.spring.SpotReview</class>
<class>com.windy.spring.User</class>
<class>com.windy.spring.UserAccount</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
生成项目时,还会生成JpaConfiguration类:
import java.util.HashMap;
import java.util.Map;
import org.hibernate.cache.HashtableCacheProvider;
import org.hibernate.dialect.H2Dialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class JpaConfiguration {
@Value("#{dataSource}")
private javax.sql.DataSource dataSource;
@Bean
public Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<String, Object>();
props.put("hibernate.dialect", H2Dialect.class.getName());
props.put("hibernate.cache.provider_class", HashtableCacheProvider.class.getName());
return props;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.H2);
return hibernateJpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager( localContainerEntityManagerFactoryBean().getObject() );
}
@Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(this.dataSource);
lef.setJpaPropertyMap(this.jpaProperties());
lef.setJpaVendorAdapter(this.jpaVendorAdapter());
return lef;
}
}
当然,我还有实体。我的app-context.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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<description>Example configuration to get you started.</description>
<jdbc:embedded-database id="dataSource" type="H2" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="com.windy.spring" />
</beans>
我想访问我的mysql数据库服务器,连接的url如下(带有用户名和密码) JDBC:MySQL的://本地主机:3306 / mynewdb&#34 ;. 我不明白我必须在哪里指示使用连接的jdbc参数,因为我得到以下日志:
2012-01-30 21:14:05,625 INFO [org.springframework.test.context.TestContextManager] - <@TestExecutionListeners is not present for class [class com.windy.spring.OrderPersistenceTests]: using defaults.>
2012-01-30 21:14:05,774 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [com/windy/spring/OrderPersistenceTests-context.xml]>
2012-01-30 21:14:05,930 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [META-INF/spring/app-context.xml]>
2012-01-30 21:14:06,180 INFO [org.springframework.context.support.GenericApplicationContext] - <Refreshing org.springframework.context.support.GenericApplicationContext@2d342ba4: startup date [Mon Jan 30 21:14:06 CET 2012]; root of context hierarchy>
2012-01-30 21:14:06,514 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3d3cdaa: defining beans [dataSource,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,jpaConfiguration,jpaDaoRole,jpaDaoUser,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,jpaProperties,jpaVendorAdapter,transactionManager,localContainerEntityManagerFactoryBean]; root of factory hierarchy>
2012-01-30 21:14:06,549 INFO [org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory] - <Creating embedded database 'dataSource'>
2012-01-30 21:14:06,631 INFO [com.windy.spring.JpaDao] - <class com.windy.spring.Role>
2012-01-30 21:14:06,736 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] - <Building JPA container EntityManagerFactory for persistence unit 'application'>
2012-01-30 21:14:06,857 INFO [org.hibernate.annotations.common.Version] - <Hibernate Commons Annotations 3.2.0.Final>
2012-01-30 21:14:06,865 INFO [org.hibernate.cfg.Environment] - <Hibernate 3.6.0.Final>
2012-01-30 21:14:06,867 INFO [org.hibernate.cfg.Environment] - <hibernate.properties not found>
2012-01-30 21:14:06,870 INFO [org.hibernate.cfg.Environment] - <Bytecode provider name : javassist>
2012-01-30 21:14:06,873 INFO [org.hibernate.cfg.Environment] - <using JDK 1.4 java.sql.Timestamp handling>
2012-01-30 21:14:06,942 INFO [org.hibernate.ejb.Version] - <Hibernate EntityManager 3.6.0.Final>
2012-01-30 21:14:06,960 INFO [org.hibernate.ejb.Ejb3Configuration] - <Processing PersistenceUnitInfo [
name: application
...]>
2012-01-30 21:14:07,089 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.FavoriteSport>
2012-01-30 21:14:07,132 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.FavoriteSport on table favorite_sport>
2012-01-30 21:14:07,190 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.FavoriteSpot>
2012-01-30 21:14:07,190 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.FavoriteSpot on table favorite_spot>
2012-01-30 21:14:07,195 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.FavoriteUser>
2012-01-30 21:14:07,195 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.FavoriteUser on table favorite_user>
2012-01-30 21:14:07,198 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.Role>
2012-01-30 21:14:07,198 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.Role on table Role>
2012-01-30 21:14:07,226 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.Sport>
2012-01-30 21:14:07,226 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.Sport on table Sport>
2012-01-30 21:14:07,229 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.Spot>
2012-01-30 21:14:07,229 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.Spot on table Spot>
2012-01-30 21:14:07,244 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.SpotReview>
2012-01-30 21:14:07,244 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.SpotReview on table spot_review>
2012-01-30 21:14:07,250 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.User>
2012-01-30 21:14:07,251 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.User on table User>
2012-01-30 21:14:07,263 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.windy.spring.UserAccount>
2012-01-30 21:14:07,264 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.windy.spring.UserAccount on table user_account>
2012-01-30 21:14:07,273 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.Role.users -> User>
2012-01-30 21:14:07,275 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.Sport.favoriteSports -> favorite_sport>
2012-01-30 21:14:07,275 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.Spot.favoriteSpots -> favorite_spot>
2012-01-30 21:14:07,275 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.Spot.spotReviews -> spot_review>
2012-01-30 21:14:07,276 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.favoriteSports -> favorite_sport>
2012-01-30 21:14:07,276 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.favoriteSpots -> favorite_spot>
2012-01-30 21:14:07,276 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.favoriteUsers1 -> favorite_user>
2012-01-30 21:14:07,276 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.favoriteUsers2 -> favorite_user>
2012-01-30 21:14:07,277 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.spotReviews -> spot_review>
2012-01-30 21:14:07,277 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: com.windy.spring.User.userAccounts -> user_account>
2012-01-30 21:14:07,279 INFO [org.hibernate.cfg.Configuration] - <Hibernate Validator not found: ignoring>
2012-01-30 21:14:07,301 INFO [org.hibernate.validator.util.Version] - <Hibernate Validator 4.1.0.Final>
2012-01-30 21:14:07,309 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2012-01-30 21:14:07,384 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2012-01-30 21:14:07,395 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2012-01-30 21:14:07,399 INFO [org.hibernate.cfg.search.HibernateSearchEventListenerRegister] - <Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.>
2012-01-30 21:14:07,404 INFO [org.hibernate.connection.ConnectionProviderFactory] - <Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider>
2012-01-30 21:14:07,408 INFO [org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider] - <Using provided datasource>
2012-01-30 21:14:07,568 INFO [org.hibernate.cfg.SettingsFactory] - <Database ->
name : H2
version : 1.3.156 (2011-06-17)
major : 1
minor : 3>
2012-01-30 21:14:07,568 INFO [org.hibernate.cfg.SettingsFactory] - <Driver ->
name : H2 JDBC Driver
version : 1.3.156 (2011-06-17)
major : 1
minor : 3>
2012-01-30 21:14:07,589 INFO [org.hibernate.dialect.Dialect] - <Using dialect: org.hibernate.dialect.H2Dialect>
2012-01-30 21:14:07,599 INFO [org.hibernate.engine.jdbc.JdbcSupportLoader] - <Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4>
2012-01-30 21:14:07,600 INFO [org.hibernate.transaction.TransactionFactoryFactory] - <Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory>
2012-01-30 21:14:07,601 INFO [org.hibernate.transaction.TransactionManagerLookupFactory] - <No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)>
2012-01-30 21:14:07,601 INFO [org.hibernate.cfg.SettingsFactory] - <Automatic flush during beforeCompletion(): disabled>
2012-01-30 21:14:07,601 INFO [org.hibernate.cfg.SettingsFactory] - <Automatic session close at end of transaction: disabled>
2012-01-30 21:14:07,601 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC batch size: 15>
2012-01-30 21:14:07,601 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC batch updates for versioned data: disabled>
2012-01-30 21:14:07,602 INFO [org.hibernate.cfg.SettingsFactory] - <Scrollable result sets: enabled>
2012-01-30 21:14:07,602 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC3 getGeneratedKeys(): enabled>
2012-01-30 21:14:07,602 INFO [org.hibernate.cfg.SettingsFactory] - <Connection release mode: auto>
2012-01-30 21:14:07,603 INFO [org.hibernate.cfg.SettingsFactory] - <Default batch fetch size: 1>
2012-01-30 21:14:07,603 INFO [org.hibernate.cfg.SettingsFactory] - <Generate SQL with comments: disabled>
2012-01-30 21:14:07,603 INFO [org.hibernate.cfg.SettingsFactory] - <Order SQL updates by primary key: disabled>
2012-01-30 21:14:07,603 INFO [org.hibernate.cfg.SettingsFactory] - <Order SQL inserts for batching: disabled>
2012-01-30 21:14:07,603 INFO [org.hibernate.cfg.SettingsFactory] - <Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory>
2012-01-30 21:14:07,606 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - <Using ASTQueryTranslatorFactory>
2012-01-30 21:14:07,606 INFO [org.hibernate.cfg.SettingsFactory] - <Query language substitutions: {}>
2012-01-30 21:14:07,606 INFO [org.hibernate.cfg.SettingsFactory] - <JPA-QL strict compliance: enabled>
2012-01-30 21:14:07,606 INFO [org.hibernate.cfg.SettingsFactory] - <Second-level cache: enabled>
2012-01-30 21:14:07,606 INFO [org.hibernate.cfg.SettingsFactory] - <Query cache: disabled>
2012-01-30 21:14:07,607 INFO [org.hibernate.cfg.SettingsFactory] - <Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge>
2012-01-30 21:14:07,612 INFO [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge] - <Cache provider: org.hibernate.cache.HashtableCacheProvider>
2012-01-30 21:14:07,613 INFO [org.hibernate.cfg.SettingsFactory] - <Optimize cache for minimal puts: disabled>
2012-01-30 21:14:07,613 INFO [org.hibernate.cfg.SettingsFactory] - <Structured second-level cache entries: disabled>
2012-01-30 21:14:07,620 INFO [org.hibernate.cfg.SettingsFactory] - <Statistics: disabled>
2012-01-30 21:14:07,620 INFO [org.hibernate.cfg.SettingsFactory] - <Deleted entity synthetic identifier rollback: disabled>
2012-01-30 21:14:07,620 INFO [org.hibernate.cfg.SettingsFactory] - <Default entity-mode: pojo>
2012-01-30 21:14:07,620 INFO [org.hibernate.cfg.SettingsFactory] - <Named query checking : enabled>
2012-01-30 21:14:07,620 INFO [org.hibernate.cfg.SettingsFactory] - <Check Nullability in Core (should be disabled when Bean Validation is on): disabled>
2012-01-30 21:14:07,640 INFO [org.hibernate.impl.SessionFactoryImpl] - <building session factory>
2012-01-30 21:14:07,894 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - <Not binding factory to JNDI, no JNDI name configured>
2012-01-30 21:14:07,900 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <Running hbm2ddl schema update>
2012-01-30 21:14:07,900 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <fetching database metadata>
2012-01-30 21:14:07,930 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <updating schema>
2012-01-30 21:14:07,931 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2012-01-30 21:14:07,950 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Role>
2012-01-30 21:14:07,951 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Sport>
2012-01-30 21:14:07,952 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Spot>
2012-01-30 21:14:07,953 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: User>
2012-01-30 21:14:07,954 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_sport>
2012-01-30 21:14:07,955 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_spot>
2012-01-30 21:14:07,956 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_user>
2012-01-30 21:14:07,957 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: spot_review>
2012-01-30 21:14:07,958 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: user_account>
2012-01-30 21:14:07,959 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Role>
2012-01-30 21:14:07,960 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Sport>
2012-01-30 21:14:07,961 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Spot>
2012-01-30 21:14:07,962 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: User>
2012-01-30 21:14:07,963 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_sport>
2012-01-30 21:14:07,964 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_spot>
2012-01-30 21:14:07,966 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: favorite_user>
2012-01-30 21:14:07,967 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: spot_review>
2012-01-30 21:14:07,967 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: user_account>
2012-01-30 21:14:08,053 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <schema update complete>
2012-01-30 21:14:08,124 INFO [com.windy.spring.JpaDao] - <class com.windy.spring.User>
2012-01-30 21:14:08,253 DEBUG [org.hibernate.SQL] - <select role0_.id_role as id1_3_0_, role0_.description as descript2_3_0_ from Role role0_ where role0_.id_role=?>
2012-01-30 21:14:08,262 INFO [org.springframework.context.support.GenericApplicationContext] - <Closing org.springframework.context.support.GenericApplicationContext@2d342ba4: startup date [Mon Jan 30 21:14:06 CET 2012]; root of context hierarchy>
2012-01-30 21:14:08,263 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3d3cdaa: defining beans [dataSource,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,jpaConfiguration,jpaDaoRole,jpaDaoUser,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,jpaProperties,jpaVendorAdapter,transactionManager,localContainerEntityManagerFactoryBean]; root of factory hierarchy>
2012-01-30 21:14:08,263 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] - <Closing JPA EntityManagerFactory for persistence unit 'application'>
2012-01-30 21:14:08,263 INFO [org.hibernate.impl.SessionFactoryImpl] - <closing>
任何人都知道我做错了什么?
提前感谢您的帮助
Danilo
答案 0 :(得分:0)
生成代码时出现问题:您不了解生成的代码,因为您没有阅读javadoc和参考手册。这里的关键是DataSource。这是创建JDBC连接的类。您在app-context.xml文件中将其配置为H2类型的嵌入式数据库的数据源。您需要一个真正的池数据源,创建与MySQL数据库的连接。当然,JPA供应商适配器的方言和数据库类型也必须更改为MySQL。
有关如何在Spring中配置DataSource的信息,请参阅http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#jdbc-datasource。