大家好我在尝试将spring 3.0与hibernate 3.1集成时遇到问题,为什么我会遇到这种类型的错误。在" HibernateDAO"我刚刚使用的课程#34; autowired"技术为" HibernateTemplate"它的投掷错误...... 我随函附上" applicationcontext"和" web.xml"
applicationContext:@
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" >
<!--<context:annotation-config />-->
<mvc:annotation-driven/>
<context:component-scan base-package="com.spring" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/>
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="bs" class="com.spring.BookServiceImpl" />
<bean id="hbdao" class="com.spring.HibernateBookDAO" />
<bean id="htemp" class="org.springframework.orm.hibernate3.HibernateTemplate" autowire="constructor" />
<!--<bean id="txManger" class="org.springframework.orm.hibernate3.TransactionManager" autowire="byName" />-->
<!--<bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.hbm2ddl.auto" value="update" />
</map>
</property>
<property name="mappingResources">
<list>
<value>com/spring/book.hbm.xml</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://loacalhost:3306/napiertest">
</property>
<property name="username" value="root"></property>
<property name="password" value="napier"></property>
</bean>
</beans>
web.xml:@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>applicationContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>applicationContext</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
在您的情况下,您的applicationContext Dispatcher servlet具有* .do扩展名。
<servlet-mapping>
<servlet-name>applicationContext</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
像这样更改你的控制器..你的RequestMapping应该有.do扩展名。请求来自带有.do扩展名的web.xml,请求应与您的控制器@RequestMapping注释匹配。所以添加这样,
@Controller
@RequestMapping("/")
public class AppController {
@RequestMapping(value="/home.do" method=RequestMethod.GET)
public String SampleMethod(Model model){