2013年9月26日星期四

springmvc + spring + mybias framework oracle database Rom

I use spring mvc + spring + mybatis framework to build a web project with oracle database connection configuration file is always Rom ( configuration file is correct ) , the configuration file into mysql connection is normal with code directly connect oracle database connection is normal , but with the configuration file is always connected, is how it happened ?
------ Solution ---------------------------------------- ----
paste the code ?
------ Solution ---------------------------------------- ----
connection does not report on the anomalies it
------ Solution --------------------- -----------------------
url = jdbc: oracle: thin: @ localhost: 1521: *** this localhost using ip
- ----- Solution --------------------------------------------
Rom, always at Diansha mistake about it .
------ Solution ---------------------------------------- ----

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: ; Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'   driver does not spread
------ Solution --------------------------------- -----------
web version of the test can not connect ?
driver jar package put position Mody
hair under the directory structure can it
------ Solution ------------------------------ --------------
database driver you go throw it in the lib tomcat .
------ For reference only -------------------------------------- -
jdbc.properties
driver=oracle.jdbc.driver.OracleDriver   
url=jdbc:oracle:thin:@localhost:1521:***
username=***
password=***


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:p="http://www.springframework.org/schema/p"
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:mvc="http://www.springframework.org/schema/mvc"
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/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/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 配置DataSource数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="2" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="1000" />
<property name="poolPreparedStatements" value="true" />

</bean>
<!-- 配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml" />
<!-- mapper和resultmap配置路径 -->
<property name="mapperLocations">
<list>
<!-- 表示在com.mcs包或以下所有目录中,以map.xml结尾所有文件 -->
<value>classpath:com/mcs/domain/McsResultMap.xml</value>

<value>classpath:com/mcs/mapper/McsSqlMapper.xml</value>
</list>
</property>
</bean>

<!-- 通过扫描的模式,扫描目录在com/hoo/mapper目录下,所有的mapper都继承SqlMapper接口的接口, 这样一个bean就可以了 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mcs.mapper" />
<property name="markerInterface"
value="com.mcs.mapper.SqlMapper" />

</bean>
<!-- 用于得到spring容器中的bean -->
<bean class="com.mcs.uitl.SpringUtil" lazy-init="false" />
<!-- 事务管理 -->
<bean id="transcantionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 加载数据源对象的属性资源文件 -->
<bean id="placeHolder"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>
<!-- 加载国际化资源 -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename">

<value>/WEB-INF/conf/i18n/messages</value>

</property>
</bean>
<!-- 本地化解析 -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<bean id="logInterceptor" class="com.mcs.uitl.LogInterceptor"></bean>
<bean id="accountService" class="com.mcs.service.impl.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
<bean id="accountDao" class="com.mcs.dao.impl.AccountDaoImpl"></bean> 
</beans>


springMvc.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="com.mcs"></context:component-scan>
<mvc:annotation-driven />
<context:annotation-config />

<!--  允许对静态资源文件的访问 -->
<mvc:default-servlet-handler />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.BeanNameViewResolver"
p:order="1" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/" p:suffix=".jsp">

</bean>
<!-- XMl及JSON视图解析器配置 -->
<bean id="userListJson"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
/>
<bean id="ListXml"
class="org.springframework.web.servlet.view.xml.MarshallingView"
p:modelKey="List" p:marshaller-ref="xmlMarshaller" />

<bean id="xmlMarshaller"
class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="streamDriver">
<bean class="com.thoughtworks.xstream.io.xml.StaxDriver" />
</property>
<property name="encoding" value="GBK"></property>
<property name="annotatedClasses">
<list>
<value></value>
</list>
</property>
</bean>

<!--  annotation默认的方法映射适配器 -->
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
</bean>
<!-- 协商多种视图解析器 -->
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
p:order="0" p:ignoreAcceptHeader="true" p:favorPathExtension="false"
p:favorParameter="true" p:parameterName="format"
p:defaultContentType="text/html">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean
class="org.springframework.web.servlet.view.BeanNameViewResolver" />

</list>
</property>
</bean>
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>

<!--  上传文件大于最大尺寸后转向出错页面 -->
<prop
key="org.springframework.web.multipart.MaxUploadSizeExceededException">
redirect:/uploadError.jsp
</prop>
                <prop key="java.lang.IllegalArgumentException">error</prop>
                <prop key="java.lang.RuntimeException">error</prop>  
</props>
</property>
<property name="defaultErrorView">
<value>fail</value>
</property>
<property name="warnLogCategory">
<value>
org.springframework.web.servlet.handler.SimpleMappingExceptionResolver
</value>
</property>

</bean>
<mvc:interceptors>
<bean class="com.mcs.uitl.LogInterceptor"></bean>
</mvc:interceptors>
</beans>

also need others?
------ For reference only -------------------------------------- -
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
    
   

<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springMvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 设定session的生命周期 -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


</web-app>

------ For reference only ----------------------------------- ----

tried using ip is still the same !
------ For reference only -------------------------------------- -

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
------ For reference only ---------------- -----------------------

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'        driver does not spread  
If the driver does not , then I wrote another code should also be directly connected not connected Yeah, but the connection code can be written directly connected successfully !
------ For reference only -------------------------------------- -



------ For reference only ----- ----------------------------------

let go , is the same !
------ For reference only -------------------------------------- -

public int add(Account account) {
try {
mapper.add(account);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 1;
}
return 0;
}


is the place to track unusual
------ For reference only --------------------------- ------------
not see it, onlookers ,

没有评论:

发表评论