您的位置:首页 > 编程语言 > Java开发

spring+springmvc+openjpa的逆向工程整合出错

2013-04-03 12:26 176 查看
整合出错了,希望大神们给我点帮助谢谢

spring-openjpa.xml:

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="SpringMvcTest" />
<!-- <property name="persistenceXmlLocation" value="classpath:openjpa-persistence.xml" /> -->
</bean>

<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="userService" class="com.mvc.service.impl.UserServiceImpl"></bean>
</beans>


persistence.xml:

<persistence-unit name="SpringMvcTest" transaction-type="RESOURCE_LOCAL">
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>

<class>com.mvc.beans.User</class>

<properties>
<!-- <property name="openjpa.ConnectionProperties"
value="DriverClassName=com.mysql.jdbc.Driver,
Url=jdbc:mysql://127.0.0.1:3306/mvctest,
MaxActive=100,
MaxWait=10000,
TestOnBorrow=true,Username=root,Password=root" /> -->

<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/mvctest" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />

<property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource" />

<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />

<!-- 允许多线程访问default broker-->
<property name="openjpa.Multithreaded" value="true" />

<!-- 自动建表语句 -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>

</properties>
</persistence-unit>
</persistence>


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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"   version="3.0">

<!-- 初始加载根目录下所有以spring开头和.xml结尾的文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring*.xml</param-value>
</context-param>

<!-- 配置映射的springmvc配置文件 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 添加spring框架的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- servletname的mapping -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.jz</url-pattern>
</servlet-mapping>

<!-- <context-param>
<param-name>contextConfigLocation</param-name>
应用上下文配置文件
<param-value>classpath:spring-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
配置spring核心servlet
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
url-pattern配置为/,不带文件后缀,会造成其它静态文件(js,css等)不能访问。如配为*.do,则不影响静态文件的访问
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.jz</url-pattern>
</servlet-mapping>   -->

<!-- 配置log4j配置文件的路径,可以是xml或 properties文件(此参数必须配)-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>

<!-- 每隔多少毫秒扫描一下配置文件的变化(此参数可选配)
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>

spring框架默认定义webAppRootKey的值为webapp.root,若不配此参数默认值就是webapp.root(因此,此参数可选配)
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>home</param-value>
</context-param> -->
<!-- 创建log4j的监听器 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

</web-app>


spring-servlet.xml:

<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:mvc="http://www.springframework.org/schema/mvc"
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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射-->
<mvc:annotation-driven />
<!-- 启动包扫描功能,以便注册带有@Controller、@Service、@repository、@Component等注解的类成为spring的bean -->
<context:component-scan base-package="com.mvc.controller" />
<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/view/" p:suffix=".jsp" />
</beans>


junit测试类:

public class UserTestJunit {
private static UserService userService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
try {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-openjpa.xml");
userService = (UserService) context.getBean("userService");
} catch (Exception e) {
e.printStackTrace();
}
}

@Test
public void test() {
User user = new User();
user.setUserName("aa");
user.setPassWord("123456");
userService.save(user);
}
}


报错信息:








内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐