当前位置:编程学习 > JAVA >>

Spring的配置文件的问题求教

web.xml文件的配置


<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>
    <servlet-name>fanfu</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
    
    
    <servlet-mapping>
        <servlet-name>fanfu</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>


fanfu-servlet.xml内容

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
         p:viewClass="org.springframework.web.servlet.view.JstlView"
         p:prefix="/WEB-INF/jsp/"
         p:suffix=".jsp"/>

applicationContext.xml的内容

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-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/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="dao" />
    <context:component-scan base-package="service" />
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/>
    <aop:config proxy-target-class="true">
        <aop:pointcut id="serviceMethod" expression="execution(* service..*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
    </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>

    </tx:advice>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close"
          p:driverClassName="com.mysql.jdbc.Driver"
          p:url="jdbc:mysql://localhost:3306/易做图db"
          p:username="root"
          p:password="890326"/>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
          p:dataSource-ref="dataSource"/>


以上内容是没有问题的,对于web包的没有做索引扫描, 问题就在于此:
   <context:component-scan base-package="web"/>加入,如果加入在fanfu-servlet.xml中就不会有问题,如果配置在applicationContext.xml中就会出现问题,报:

2012-8-13 9:59:00 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'fanfu'

这个有特殊的要求吗,为什么service和dao能配置在那,而web包中就会有问题呢。ps:web包中配置的是controller,是基于注解的。service和dao也是基于注解的,真心求教! --------------------编程问答-------------------- 你那web包是在根目录下吗,前面没加com或者cn什么的吗 --------------------编程问答-------------------- 是在根路径下,注意是放在其中一个配置文件里面就有用,另一个没用,这证明不是路径问题吧。而且Spring如果你的配置无效是会报异常的哦
补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,