`
streammoon
  • 浏览: 25215 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

maven+springmvc+spring data jpa

 
阅读更多
pom.xml:

<properties>
<struts2.springPlatformVersion>
3.2.0.RELEASE
</struts2.springPlatformVersion>
</properties>
<dependencies>

<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.6.10.Final</version>
</dependency>

<dependency>
<groupId>taglibs</groupId>
<artifactId>request</artifactId>
<version>1.0.1</version>
</dependency>

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>standard</groupId>
<artifactId>standard</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${struts2.springPlatformVersion}</version>
</dependency>





<!-- Commons -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>


<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>

<dependency>
<groupId>net.sf.oval</groupId>
<artifactId>oval</artifactId>
<version>1.80</version>
</dependency>

<!--

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<classifier>jdk15</classifier>
<version>2.3</version>
</dependency>

<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.5.8</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.5</version>
</dependency>
  
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.1.0</version>
        </dependency>
!-- Spring jpa -->
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-jpa</artifactId>
  <version>1.2.0.RELEASE</version>
</dependency>
</dependencies>
<!-- Spring jpa -->
<repositories>
  
   <repository>
     <id>spring-snapshot</id>
     <name>Spring Maven SNAPSHOT Repository</name>
     <url>http://repo.springsource.org/libs-snapshot</url>
     </repository>
</repositories>

  <build>
    <finalName>MvnTest</finalName>
    <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>

</plugins>
  </build>

========================================================

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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
">
   <context:annotation-config/>
      <context:component-scan base-package="com.jpa.app" />

      <bean   class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
   
<bean id="entityManagerFactory"    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   
     <property name="dataSource" ref="dataSource" /> 
     <property name="persistenceXmlLocation" value="classpath:persistence.xml"/>  
    
     <property name="jpaVendorAdapter">         
           <bean   class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">               
                  <property name="database" value="ORACLE" />         
           </bean>       
    </property>
</bean>
<!-- mysql

<bean id="dataSource"    class="org.springframework.jdbc.datasource.DriverManagerDataSource">    
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />    
    <property name="url" value="jdbc:mysql://localhost/jpatest" />    
    <property name="username" value="root" />     
   <property name="password" value="root" />    
</bean>   
-->  
<!-- oracle-->
<bean id="dataSource"    class="org.springframework.jdbc.datasource.DriverManagerDataSource">    
     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
    <property name="username" value="jpatest" />     
   <property name="password" value="123" />    
</bean>

<bean id="transactionManager"   class="org.springframework.orm.jpa.JpaTransactionManager">   
     <property name="entityManagerFactory" ref="entityManagerFactory" />  
</bean>   

<tx:annotation-driven transaction-manager="transactionManager" />  
  
<jpa:repositories base-package="com.jpa.app.dao" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
</beans>
================================================

Action:

@Controller
@RequestMapping(value = "/loginAction")
public class LoginAction extends BaseAction {
  @Autowired
  private LoginService service;
 
  @RequestMapping(value="/login")
  public String login(HttpServletRequest request){
    UserInfo em = new UserInfo();
    em.setUserName("aa");
    em.setPassword("111");

    UserInfo user = service.login(em);
   .....
  }
}
====================
Service:

@Service
@Transactional
public class LoginService {
  @Autowired
   private LoginRepo loginRepo;

  public UserInfo login(UserInfo user){
    List<UserInfo> list = loginRepo.login(user.getUserName(),user.getPassword());
if(null!=list&&!list.isEmpty()){
return list.get(0);
}
return null;

}

=======================
Dao:

public interface LoginRepo extends CrudRepository<UserInfo, Integer>{
  @Query("select new UserInfo(t.id,t.userName,t.cnName,t.lev,d) from UserInfo t left join t.dept d where t.userName=? and t.password=?")
  public List<UserInfo> login(String userName,String password);
}
分享到:
评论
2 楼 endual 2013-07-16  
可以运行的,要是添加junit的话就棒了
oracle驱动还有改成mysql也不错啊
1 楼 蒙太奇 2013-06-02  
运行不了啊,报错!
严重: Servlet.service() for servlet jsp threw exception
java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/jasper/servlet/JasperLoader) previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest"
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
	at java.lang.Class.getDeclaredMethods(Class.java:1808)
	at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:226)
	at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:148)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:722)

相关推荐

    Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA

    在现代Java Web开发中,"Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA"是一个常见的架构组合,被广泛应用于构建企业级应用程序。这个组合通常被称为"SSM",其中"M"代表Maven,"S"代表Spring,包括Spring核心...

    maven+springmvc+redis+mybatis整合

    Spring MVC允许开发者通过注解将控制器方法与URL映射,方便地处理HTTP请求,并且可以与Spring的其他模块(如Spring Data JPA、Spring Security等)无缝集成。 Redis是一个开源的、高性能的键值数据库,特别适合用作...

    spring+SpringMVC+Spring Data JPA+Maven(增删该查功能齐全)

    技术架构:SpringMVC4+Spring4+Spring Data JPA+hibernate4+Maven 声明:查了好多资料,下载了好多代码,发现没有几个能运行起来的,于是写下此代码,希望能够帮助后来者。此程序导入&创建DB,配置好maven便可运行。...

    CRM营销系统 spring+springmvc+springdatajpa+jsp+maven

    这个项目采用了Spring、SpringMVC、SpringDataJPA和JSP等技术,结合Maven进行构建和管理依赖。以下将详细介绍这些关键技术及其在CRM系统中的应用。 1. Spring框架:Spring是一个全面的后端开发框架,它提供依赖注入...

    手动创建 SpringMvc +SpringDataJpa+Hibernate+ freemarker mavenProject+ 环境切换 webDemo

    在本项目中,我们主要探讨如何手动构建一个基于SpringMVC、Spring Data JPA、Hibernate以及FreeMarker模板引擎的Maven工程,同时实现环境切换功能。这个基础框架为日常开发工作提供了必要的支持。 首先,SpringMVC...

    maven + springmvc 入门实例

    **SpringMVC与Maven入门实例详解** 在Java Web开发中,SpringMVC和Maven是两个非常重要的工具。...继续深入学习,你还可以掌握Spring Security、Spring Data JPA等扩展,进一步提升你的Web开发能力。

    SpringMVC+Spring+Spring Data JPA+Maven

    技术架构:SpringMVC3+Spring3.1.2+Spring Data JPA+Maven 声明:该应用仅仅是技术研究:Spring Data JPA的配置和常见api的使用&maven构建项目,其他技术不在此研究 内涵sql和各种Spring Data JPA测试和案例,导入&...

    spring+springmvc+spring data jpa+mysql

    标题 "spring+springmvc+spring data jpa+mysql" 涉及到的是一个基于Java的Web开发技术栈,主要用于构建高效、灵活的企业级应用程序。这个技术组合包括四个主要组件: 1. **Spring框架**:这是一个全面的企业级应用...

    Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA+JdbcTemplate

    在"Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA+JdbcTemplate"的DEMO中,开发者通常会创建一个Maven工程,配置相关依赖,然后分别设置Spring的配置文件(如`applicationContext.xml`)、SpringMVC的配置文件...

    2017 spring data jpa+spring4.2+springmvc+hibernate4.3 maven环境intellij idea增删改查实例

    综上所述,这个实例提供了一个完整的Java Web开发环境,展示了如何使用Spring Data JPA、Spring 4.2、Spring MVC和Hibernate 4.3进行数据操作,以及如何利用Maven进行项目管理,同时借助IntelliJ IDEA提升开发效率。...

    spring4.x+springdatajpa+springmvc+maven搭建

    通过整合Spring 4.x、Spring Data JPA、Spring MVC和Maven,我们可以快速构建出一个高效、可维护的Web应用,其中数据访问层借助Spring Data JPA实现了简洁的数据库操作,业务逻辑由Spring MVC处理,而项目的构建和...

    idea 搭建springboot 集成mybatis+springmvc

    - 在“Dependencies”部分,搜索并添加“Spring Web”和“Spring Data JPA”依赖,这将为Spring MVC和数据访问提供基础支持。 3. **添加MyBatis依赖** - 在`pom.xml`文件中,手动添加MyBatis和相关依赖,例如`...

    spring4+springdatajpa+springmvc+angularjs+bootstrap+maven

    标题 "spring4+springdatajpa+springmvc+angularjs+bootstrap+maven" 提供了关于一个基于Java的Web开发框架的信息。这个框架整合了多个关键的技术组件,用于构建高效、现代化的Web应用。让我们逐一深入理解这些技术...

    SpringMVC+Spring+JPA+Maven框架搭建

    SpringMVC+Spring+JPA+Maven框架搭建 SpringMVC+Spring+JPA+Maven框架的搭建涉及到一系列的技术组件,其中SpringMVC是Spring框架的一个模块,用于构建Web应用,提供MVC架构;Spring框架是一套全面的企业级应用开发...

    maven+nexus+spring+springmvc+mybatis+generator+mysql搭建框架

    与SpringData JPA、MyBatis等框架配合,可以实现高效的数据操作。 在实际搭建过程中,我们需要: 1. 安装并配置Maven,设置本地仓库和Nexus私服。 2. 在Nexus中创建并配置私有Maven仓库。 3. 使用Maven创建项目,...

    基于javaConfig的springDataJpa+dubbo+springMvc搭建

    在提供的文件列表中,"基于javaConfig的springDataJpa+dubbo+springMvc搭建.txt"可能包含详细的搭建步骤和示例代码,"pom.xml"是项目的依赖管理文件,"sdk"和"web"、"app"可能是项目代码或资源文件的目录。...

    maven+spring+spring mvc+mybatis整合实现ssm通用基础开发框架

    SSM(Spring、Spring MVC、MyBatis)是Java Web开发中常见的三层架构组合,用于构建高效、灵活的...在实际开发中,还可以结合其他工具和库,如Spring Boot、Spring Data JPA等,进一步提升开发效率和项目的可维护性。

    springmvc+springDatajpa+maven

    在“springmvc+springDatajpa+maven”这个项目中,这三个技术协同工作以实现高效的 Web 应用开发。Spring MVC 负责处理 Web 请求,Spring Data JPA 通过 Hibernate 与数据库交互,而 Maven 则管理项目的构建和依赖。...

Global site tag (gtag.js) - Google Analytics