spring中配置MySql数据源,怎样配置数据库信息

2025-04-18 19:06:40
推荐回答(1个)
回答1:

jdbc.xml


      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      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:jpa="http://www.springframework.org/schema/data/jpa"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
   http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
   http://www.springframework.org/schema/data/jpa 
   http://www.springframework.org/schema/data/jpa/spring-jpa-4.0.xsd"
      default-autowire="byName">
 
 
   
           init-method="init" destroy-method="close" autowire="byName">
      
      
      
      
      
      
 
      
      
      
      
 
 
      
      
      
      
 
      
      
 
      
      
 
      
      
 
      
      
      
      
 
      
      
      
   
 
 
   
      
   
   
           class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      
   
 
   
                       expression="execution(* cn.cq.shenyun.service.*.*(..))"/>
      
   

 
   
      
      
         
         
         
         
         
         
         
         
      

   
   
   
   
   
 

jdbc.properties

#DataSource settings
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/sprimy?useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=123456