2 snailandjava snailandjava 于 2015.06.21 12:58 提问

spring mvc datajpa整合时出现找不到类的情况,百度了很多都没有解决问题。

用srping mvc和jpa写一个helloworld,没想到还跑不起来
不知道哪里出错了,可能是配置没做好,这里还请大家帮忙看看是什么没问题。
下面是我的代码:

这是个controller

 package com.ll.together.controller;

import com.ll.together.service.LoginBQqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloWorldController {

    @Autowired
    public LoginBQqService loginBq;
    @RequestMapping("/hello.htm")
    @ResponseBody
    public String hello() {
        loginBq.findAll();
        return "mysldks";
    }



}

下面是 LoginBQqService

 package com.ll.together.service;

import com.ll.together.entity.QqUser;
import org.springframework.data.repository.CrudRepository;

/**
 * Created by xiaolongren on 15/6/13.
 */
public interface LoginBQqService extends CrudRepository<QqUser,String> {
}
下面是applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
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:task="http://www.springframework.org/schema/task"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
>
context:annotation-config/
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">


class="org.springframework.orm.jpa.JpaTransactionManager">
ref="entityManagerFactory"/>


class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">

class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor">


task:annotation-driven/


下面是dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
                            http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.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.xsd"
        >

    <mvc:annotation-driven/>
    <context:annotation-config/>
    <context:component-scan base-package="com.ll.together"/>
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/page/"/>
        <property name="suffix" value=".jsp"/>
    </bean>


</beans>

下面是web.xl

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

         version="3.1">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
</web-app>

访问:http://localhost:8080/hello.htm报错
[2015-06-21 12:46:48,471] Artifact spingjpa:war exploded: Artifact is being deployed, please wait...
21-Jun-2015 12:46:50.950 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'dispatcher': initialization started
21-Jun-2015 12:46:50.980 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Jun 21 12:46:50 CST 2015]; root of context hierarchy
21-Jun-2015 12:46:51.026 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
21-Jun-2015 12:46:52.080 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/hello.htm],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.ll.together.controller.HelloWorldController.hello()
21-Jun-2015 12:46:52.082 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/hh],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.ll.together.controller.UserController.index()

java.lang.NoClassDefFoundError: org/springframework/data/repository/CrudRepository

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Spring SpringMVC Hibernate整合时的一些问题
目录结构为: (1)springMVC + spring: exclude,include SpringMVC 专注于Controller,其他的放到Spring中 SpringMVC配置为: Spring配置为: (2)c3p0数据源和普通的jdbc 配置中的name是有区别的,还是不一样
springmvc 和 mybatis 整合时因缺少jar包引起的错误
启动tomcat时会出现以下错误 Error creating bean with name ‘dataSource’ defined in ServletContext resource [/WEB-INF/classes/spring/applicationContext-dao.xml]: BeanPostProcessor before instantiation of bean fail
SpringMVC与Mybatis框架整合遇到的坑
最近在做springmvc与mybatis的项目,遇到一些比较坑的问题。花了许多时间却发现其实解决的办法很简单。这里主要是讲我自己在整合这两个框架的时候遇到的一些问题做一个整理。希望遇到和我同样问题的小伙伴可以不被坑。坑一:nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (
【SpringMVC学习04】Spring、MyBatis和SpringMVC的整合
前两篇springmvc的文章中都没有和mybatis整合,都是使用静态数据来模拟的,但是springmvc开发不可能不整合mybatis,另外mybatis和spring的整合我之前学习mybatis的时候有写过一篇,但是仅仅是整合mybatis和spring,所以这篇文章我系统的总结一下spring、mybatis和springmvc三个框架的整合(后面学习到maven时,我会再写一篇使用ma
ssi整合时之beans.xml
ssi整合时spring的总配置文件·
ssm三大框架手动整合时遇到的错误与注意总结( 一)
初步学习ssm三大框架手动整合时常见的一些错误
struts2整合spring报404
第一次整合ssh就碰到这么莫名奇妙的问题实在是让人头疼,只好naizhe
ssh所用到的jar包
struts2、spring、hibernate整合时用到的jar包
struts2和spring的两种整合方式
首先,来看看如何让Spring 来管理Action. 在struts.xml中加入 "struts.objectFactory" value="spring" /> 有两种整合方式: (1) 把Action配置在beans.xml里,利用Spring初始化Action的bean: 将Struts的业务逻辑控制器类配置在Spring的配置文件中,Action中引用的业务类一并注入。
SpringMVC与ssm的整合
1.SpringMVC的框架原理图: 第一步:发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求HandlerMapping查找 Handler 可以根据xml配置、注解进行查找 第三步:处理器映射器HandlerMapping向前端控制器返回Handler 第四步:前端控制器调用处理器适配器去执行Handler 第五步:处理器适配器去执