- 浏览: 128552 次
- 性别:
- 来自: 来处
文章分类
最新评论
-
107x:
不错,谢谢!
reponse 下载文件设置 -
junko2013:
...
UEditor Java 上传图片配置 -
hh792000:
折腾了好久好久,终于在看了楼主这篇文章后解决了问题,感激ing ...
Spring3.0MVC和Hibernate基于annotation注解的整合 -
xlaohe1:
lifeiez 写道请教高人:前台提交一个图片到后台,@Req ...
UEditor Java 上传图片配置 -
lifeiez:
请教高人:前台提交一个图片到后台,@RequestMappin ...
UEditor Java 上传图片配置
Spring3.0MVC和Hibernate基于annotation注解的整合
springmvc和hibernate的annotation集合:
首先web.xml
然后是applicationContext.xml
spring-serlvet.xml
entity:
userdaoimpl
userserviceimpl
usercontroller
有意见和建议请留下..
首先检查你的jar包是否正确,
然后在看看你的配置
这个不能写错,
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
对的。和web.xml同级。
有时间我会加上结构图的。
首先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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>hibernateAspringmvc</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <!-- this is 'spring' name for your spring-servlet.xml --> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.xl</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
然后是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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:p="http://www.springframework.org/schema/p" 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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd" default-autowire="byName" default-lazy-init="true"> <!-- this pack must include xxx-servlet.xml's pack. --> <context:component-scan base-package="org.xlaohe1" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 这几句在spring hibernate的注解整合中可以不需要 因为下面的2就是扫描指定路劲下的实体进行映射 --> <!-- 1======================= --> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="annotatedClasses"><!-- the must have. before this is mapping,now is entity --> <list> <value>org.xlaohe1.model.User</value> </list> </property> <!-- 1======================= --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.jdbc.batch_size">50</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> </props> </property> <!-- 2======================= --> <!-- 自动扫描指定位置下的实体文件进行映射 --> <property name="packagesToScan" value="org.xlaohe1.model" /> <!-- 2======================= --> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
spring-serlvet.xml
<?xml version="1.0" encoding="UTF-8"?> <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"> <!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 --> <context:component-scan base-package="org.xlaohe1.web"/> <!--启动Spring MVC的注解功能,完成请求和注解POJO的映射 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> --> <mvc:annotation-driven/> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
entity:
package org.xlaohe1.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "users", catalog = "test") public class User { private Integer id; private String username; private String password; private Integer age; public User() { super(); } @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "id") public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Column(name = "username") public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Column(name = "password") public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Column(name = "age") public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } }
userdaoimpl
package org.xlaohe1.dao.impl; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.stereotype.Repository; import org.xlaohe1.dao.IUserDao; import org.xlaohe1.model.User; @Repository public class UserDaoImpl extends HibernateDaoSupport implements IUserDao { @SuppressWarnings("unchecked") @Override public List<User> findAllUsers() { String hql = "FROM User"; return getHibernateTemplate().find(hql); } }
userserviceimpl
package org.xlaohe1.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.xlaohe1.dao.IUserDao; import org.xlaohe1.model.User; import org.xlaohe1.service.IUserService; @Service @Transactional public class UserServiceImpl implements IUserService { @Autowired IUserDao userDao; @Override //@Transactional(propagation=Propagation.SUPPORTS,readOnly=true) public List<User> findAllUsers() { return userDao.findAllUsers(); } }
usercontroller
package org.xlaohe1.web; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.xlaohe1.model.User; import org.xlaohe1.service.IUserService; @Controller public class UserController { @Autowired IUserService userService; public UserController() { } @RequestMapping(value = "/show") public ModelAndView myMethod(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception { List<User> ulst = userService.findAllUsers(); modelMap.put("users", ulst); return new ModelAndView("showUser", modelMap); } @RequestMapping(value = "/t") public ModelAndView t() { return new ModelAndView("t"); } }
有意见和建议请留下..
评论
10 楼
hh792000
2015-03-05
折腾了好久好久,终于在看了楼主这篇文章后解决了问题,感激ing
9 楼
piaomiaowc1
2013-10-09
能提供源码下载吗。楼主!!!
8 楼
reggie_ysq
2012-04-02
这个不能写错,
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
首先检查你的jar包是否正确,
然后在看看你的配置
这个不能写错,
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
可否把你的lib包用到的jar 贴出来啊? 配置,代码真的一样。 估计和包有关系吧。
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
xlaohe1 写道
reggie_ysq 写道
一摸一样的代码和配置文件,但是总是有这个错,好汉给点建议啊
首先检查你的jar包是否正确,
然后在看看你的配置
<context:component-scan base-package="org.xlaohe1.web"/>
这个不能写错,
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
可否把你的lib包用到的jar 贴出来啊? 配置,代码真的一样。 估计和包有关系吧。
7 楼
xlaohe1
2012-03-29
reggie_ysq 写道
一摸一样的代码和配置文件,但是总是有这个错,好汉给点建议啊
首先检查你的jar包是否正确,
然后在看看你的配置
<context:component-scan base-package="org.xlaohe1.web"/>
这个不能写错,
你的dao和service的注解要写对
最后你的controoler的Autowired是接口的不是实现
主要你的Autowired地方看看
6 楼
reggie_ysq
2012-03-28
一摸一样的代码和配置文件,但是总是有这个错,好汉给点建议啊
5 楼
reggie_ysq
2012-03-28
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.xlaohe1.service.IUserService org.xlaohe1.web.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.xlaohe1.service.IUserService org.xlaohe1.web.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 33 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 35 more
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /example threw load() exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 28, 2012 3:32:20 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 28, 2012 3:32:20 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 28, 2012 3:32:20 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/10 config=null
Mar 28, 2012 3:32:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1110 ms
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.xlaohe1.service.IUserService org.xlaohe1.web.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.xlaohe1.service.IUserService org.xlaohe1.web.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 33 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 35 more
Mar 28, 2012 3:32:20 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /example threw load() exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.xlaohe1.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 28, 2012 3:32:20 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 28, 2012 3:32:20 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 28, 2012 3:32:20 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/10 config=null
Mar 28, 2012 3:32:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1110 ms
4 楼
xlaohe1
2012-03-23
leageshine 写道
showUser.jsp代码能否贴出来?
<%@page import="org.springframework.ui.ModelMap"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>在此处插入标题</title> </head> <body> <br /> <table border="1"> <c:forEach var="list" items="${users}"> <tr> <td>${list.id }</td> <td>${list.username }</td> <td>${list.password }</td> <td>${list.age }</td> </tr> </c:forEach> </table> showUser page. ${loginUser } <%=request.getAttribute("loginUser") %> <a href="t.xl">remove</a> </body> </html>
3 楼
leageshine
2012-03-21
showUser.jsp代码能否贴出来?
2 楼
xlaohe1
2012-01-11
卢水发 写道
请问一下你的spring-servlet是放在web-inf下面吗?
对的。和web.xml同级。
有时间我会加上结构图的。
<servlet> <!-- this is 'spring' name for your spring-servlet.xml --> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
1 楼
卢水发
2012-01-10
请问一下你的spring-servlet是放在web-inf下面吗?
相关推荐
整合Spring MVC和Hibernate的关键在于Spring的ApplicationContext,它可以管理所有的Bean,包括Hibernate的SessionFactory和TransactionManager。在Spring配置文件中,使用@Bean注解定义这些Bean,然后通过@...
Spring 3.0 MVC 实现 REST 代码是一个关于构建基于 RESTful 风格的 Web 服务的示例。REST(Representational State Transfer)是一种架构风格,常用于设计网络应用程序,强调通过统一资源标识符(URI)来访问资源,...
Struts2、Spring2.5和Hibernate3.0是Java Web开发中三个非常重要的框架,它们各自负责不同的职责,但可以协同工作以构建高效、可维护的Web应用程序。本项目整合了这三个框架,并利用注解(Annotation)进行配置,...
Struts1.3、Hibernate3.3和Spring3.0是经典的Java企业级开发框架,它们的整合在早期Web应用开发中非常常见。这三种框架的结合提供了模型-视图-控制器(MVC)架构、对象关系映射(ORM)以及依赖注入(DI)和面向切面...
### Spring_Hibernate_JAVAX_Annotation 注解详解 #### 一、概述 本文将详细介绍与SSH(Spring+Struts+Hibernate)开发相关的注解。这些注解覆盖了多个领域,如AspectJ、Batch处理、Spring框架本身的功能(包括...
本文将详细解析"Struts2+Spring2+Hibernate3 Annotation的整合"这一主题,主要涵盖以下几个方面: 1. **Struts2框架**:Struts2是一个基于MVC设计模式的Web应用框架,用于简化Java Web应用程序的开发。它的主要功能...
本文档主要介绍了如何在MyEclipse 8.6环境中搭建一个基于Struts2.1、Spring3.0和Hibernate3.3的Java Web应用开发环境。以下是各个部分的详细说明: 1. 创建Web Project项目 在MyEclipse中创建Web Project是开始...
3. **注解驱动的开发(Annotation-based Development)**:Spring 3.0大力推广注解,如@Service、@Repository、@Controller等,使得XML配置文件大大减少,提高了开发效率。 4. **JSR-303/JSR-349 Bean Validation**...
在本项目中,我们探讨了如何整合Spring 3.0、Hibernate 3.6和Struts2.2.1这三大框架,以构建一个高效、灵活的企业级Web应用程序。这三者结合,提供了模型-视图-控制器(MVC)架构、持久层管理和AOP(面向切面编程)...
这个"Struts2+Spring2.5+Hibernate3+annotation"整合程序是为了实现高效、灵活和松耦合的Web应用架构。下面将详细介绍这三个框架的核心功能以及它们在整合中的作用。 1. Struts2:Struts2是一个基于MVC(Model-View...
2. **注解驱动开发 (Annotation-based Development)**:Spring 3.0引入了大量的注解,如`@Component`、`@Service`、`@Repository`和`@Controller`,用于简化配置,使代码更加简洁。此外,`@Autowired`和`@Qualifier`...
2. **注解驱动开发(Annotation-based Development)**:Spring 3.0引入了大量的注解,如@Service、@Controller、@Repository和@Transactional,减少了XML配置,提高了代码可读性。例如,@Autowired用于自动装配依赖,...
### 基于注解的Spring MVC+Hibernate简单入门 #### 概述 本文主要介绍如何使用基于注解的方式构建Spring MVC与Hibernate相结合的应用程序。这种方式不仅简化了配置过程,而且提高了开发效率。我们将通过一个具体的...
本项目利用一系列流行的技术栈,包括jQuery EasyUI、Struts2、Spring和Hibernate,构建了一个基于注解的CRM系统。以下将详细解析这些技术及其在项目中的应用。 **jQuery EasyUI** 是一个基于jQuery的前端框架,提供...
### Struts2+Spring2+Hibernate3+Annotation所需JAR包详解 在Java Web开发领域,Struts2、Spring2和Hibernate3是三个非常重要的框架,它们分别负责Web层、业务逻辑层和服务持久化层的功能实现。为了更好地整合这三...
Struts2、Hibernate3.5和Spring3.0是Java Web开发中的三个核心框架,它们在权限管理中扮演着重要角色。这篇详细说明将深入探讨这三个框架如何协同工作,以及如何利用注解(Annotation)来简化配置。 Struts2是一个...