急急急 项目部署到阿里云ecs上后 数据库连接问题 100分求指点

m0_37659175 2017-07-21 04:27:05
项目部署到了阿里云的ecs服务器 tomcat和mysql都在ecs上 打war包上传后 各个页面都可以正常打开 跳转 但是只要涉及到数据库的操作就会报错 一直找不到原因 数据库的db配置文件都检查了 没有错误 不知道是不是数据源的配置问题 这里贴上相关配置
希望做过lnuix部署的帮我看下

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

<!-- 引入数据库配置文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 扫描 -->
<context:component-scan base-package="cn.ludifufu.serviceimpl,cn.ludifufu.control"></context:component-scan>

<!-- 数据源 c3p0配置 -->
<bean id="dataSourceC3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="minPoolSize" value="10"></property>
<property name="maxPoolSize" value="100"></property>
<property name="maxIdleTime" value="60"></property>
<property name="initialPoolSize" value="10"></property>
</bean>

<!-- 配置myBatis的相关信息 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceC3p0"></property>
<!-- 加载mybatis.cfg.xml文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 自动扫描需要定义类别名的包,将包内的JAVA类的类名作为类别名 -->
<!-- <property name="typeAliasesPackage" value="com.hd.pojo"></property> -->
</bean>
<!-- 自动扫描所有的Mapper接口与文件 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.ludifufu.mapper"></property>
</bean>

<!--spring事务配置 -->
<!-- 事务的配置 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceC3p0" />
</bean>
<!-- 拦截器方式配置事物 -->
<tx:advice id="transactionAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 以如下关键字开头的方法使用事物 -->
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="buyfood" propagation="REQUIRED"/>
<tx:method name="order" propagation="REQUIRED"/>
<!-- 以如下关键字开头的方法不使用事物 -->
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="query*" read-only="true" />

<!-- 其他方法不使用事物 -->
<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>

<!-- 切面,将事物用在哪些对象上 -->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* cn.ludifufu.serviceimpl.*Impl.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>




<!--spring事务配置结束 -->
</beans>
<-------------------------------------------------------------------------------------------------------------------------------------------------------------------->
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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>LuDi</display-name>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param>

<!-- spring框架提供的字符集过滤器 -->
<!-- spring Web MVC框架提供了org.springframework.web.filter.CharacterEncodingFilter用于解决POST方式造成的中文乱码问题 -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 配置SpringMVC的前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 关联配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-config.xml</param-value>
</init-param>
</servlet>
<!-- http://localhost:8081/xx/abc -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<!-- 防止资源文件被spring MVC拦截 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
</web-app>

db.properties配置

driverClass=com.mysql.jdbc.Driver
validationQuery=SELECT 1
jdbcUrl=jdbc:mysql://192.168.0.27:3306/bank?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
user=root
password=122222

mybatis配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 引入db.properties文件
<properties resource="db.properties">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
</properties>-->
<!-- 开启延迟加载 -->
<settings>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
</settings>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
<!-- 该参数默认为false -->
<!-- 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 -->
<!-- 和startPage中的pageNum效果一样-->
<property name="offsetAsPageNum" value="true"/>
<!-- 该参数默认为false -->
<!-- 设置为true时,使用RowBounds分页会进行count查询 -->
<property name="rowBoundsWithCount" value="true"/>
<!-- 设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果 -->
<!-- (相当于没有执行分页查询,但是返回结果仍然是Page类型)-->
<property name="pageSizeZero" value="true"/>
<!-- 3.3.0版本可用 - 分页参数合理化,默认false禁用 -->
<!-- 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 -->
<!-- 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
<property name="reasonable" value="false"/>
<!-- 3.5.0版本可用 - 为了支持startPage(Object params)方法 -->
<!-- 增加了一个`params`参数来配置参数映射,用于从Map或ServletRequest中取值 -->
<!-- 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值 -->
<!-- 不理解该含义的前提下,不要随便复制该配置 -->
<property name="params" value="pageNum=start;pageSize=limit;"/>
<!-- always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page -->
<property name="returnPageInfo" value="check"/>
</plugin>
</plugins>
<!-- <typeAliases> -->
<!-- 给具体的单个类型指定别名
<typeAlias type="com.hd.pojo.UserBean" alias="abc"/>
-->
<!-- 给映射文件中的类型统一指定前缀,并且类型不区分大小写 -->
<!-- <package name="com.hd.pojo"/>
</typeAliases> -->



<mappers>
<!--<mapper resource="com/hd/mapper/UserbeanMapper.xml"/> -->
</mappers>


</configuration>

打开首页可以 注册的时候 数据填写完成后 点击注册
报下面的错误
...全文
438 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_25704981 2018-01-05
  • 打赏
  • 举报
回复
解决了吗? 我也遇到这个问题
qq_34533708 2017-11-11
  • 打赏
  • 举报
回复
我也遇到这种问题, 求答案
m0_37659175 2017-07-21
  • 打赏
  • 举报
回复
mybatis配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 引入db.properties文件 <properties resource="db.properties"> <property name="driver" value="oracle.jdbc.driver.OracleDriver"/> </properties>--> <!-- 开启延迟加载 --> 5楼的兄弟你看错了吧 这是注释了的 你可能没看清楚
一念永恒 2017-07-21
  • 打赏
  • 举报
回复
你试试通过阿里云服务器连接mysql后,进入mysql数据库,进入user表,然后执行:UPDATE `user` set `Host`='%' where `User`='root'
鱿鱼ing 2017-07-21
  • 打赏
  • 举报
回复
<!-- 数据源 c3p0配置 --> <bean id="dataSourceC3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driverClass}"></property> <property name="jdbcUrl" value="${jdbcUrl}"></property> <property name="user" value="${user}"></property> <property name="password" value="${password}"></property> <property name="minPoolSize" value="10"></property> <property name="maxPoolSize" value="100"></property> <property name="maxIdleTime" value="60"></property> <property name="initialPoolSize" value="10"></property> <!--每5小时检查所有连接池中的空闲连接。防止mysql wait_timeout(默认的为8小时) --> <property name="idleConnectionTestPeriod" value="18000"/> </bean> 看了一部分别人的解决办法,不知道添加上这个有没有用
Buguanjia-Ssj 2017-07-21
  • 打赏
  • 举报
回复
你db.properties里用的是mysql数据库,然后你引入配置的时候就变成oracle了
Buguanjia-Ssj 2017-07-21
  • 打赏
  • 举报
回复
你再仔细看下你的jabcUrl,看看有没有错误
m0_37659175 2017-07-21
  • 打赏
  • 举报
回复
数据库开了 我本地都能连接服务器上的数据库
鱿鱼ing 2017-07-21
  • 打赏
  • 举报
回复
那。。。。。。。。。。。。。。。 数据库开了么?
m0_37659175 2017-07-21
  • 打赏
  • 举报
回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧