Spring boot +cassandra+mysql 双数据源学习笔记

根据项目的需要,研究了一下cassandra,+mysql,nosql数据库和关系型数据库双数据源的配置。

在上一个Spring boot+cassandra的基础上,加入mysql+mybatis的配置:

application.properties加入myql配置和mybatis配置

spring.datasource.url=jdbc:mysql://172.16.7.201:3306/om_new?useUnicode=true&charaterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=123.com
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# Mybatis 
mybatis.typeAliasesPackage=com.fdway.itil.*.entity
mybatis.mapperLocations=classpath:mapper/*.xml
# cassandra (CassandraProperties)  
spring.data.cassandra.cluster-name=Test Cluster
spring.data.cassandra.keyspace-name= myspace
spring.data.cassandra.contact-points=127.0.0.1
spring.data.cassandra.port=9042

mysql数据库表

Custom

public class Custom {

	private String id;
	private String name;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}

CustomMapper

@Mapper
public interface CustomMapper {
	    public List findCustom();  
	    public int addCustom(Custom custom);  
	    public int delCustom(int id);  
}
CustomMapper.xml




	
	
		insert into custom (id, name ) values
		(#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR} )
	
	
		delete from custom where id = #{id,jdbcType=VARCHAR}
	

CustomServcie
@Service
public class CustomServiceImpl implements CustomService {
	@Autowired
    private CustomMapper customMapper;  
  
    /* (non-Javadoc)
	 * @see com.faway.itil.mysql.entity.CustomService#findCustom()
	 */
    @Override
	public List findCustom(){  
        return customMapper.findCustom();  
    }  
  
      
    /* (non-Javadoc)
	 * @see com.faway.itil.mysql.entity.CustomService#insert(com.faway.itil.mysql.entity.Custom)
	 */
    @Override
	public void insert(Custom custom) {  
        customMapper.addCustom(custom);  
          
    }  
}

customController

public class CustomController {
	@Autowired  
    private CustomService customService;  
      
    @RequestMapping("/get")  
    public List getUserInfo() {  
        List custom = customService.findCustom();
        System.out.println(custom.toString());  
        return custom;  
    }  
}

启动spring boot

访问:localhost:8086/user/list,nosql数据库,user表,

Spring boot +cassandra+mysql 双数据源学习笔记_第1张图片


访问:localhost:8086/user/list,mysql数据库,custom表,

Spring boot +cassandra+mysql 双数据源学习笔记_第2张图片

你可能感兴趣的:(Cassandra,spring,boot,双数据源)