这是配置类。
@Configuration
@PropertySource(value = { "classpath:cassandra.properties" })
@EnableCassandraRepositories(basePackages = { "com.example.demo.repository" })
public class CassnadraConfig extends AbstractCassandraConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(CassnadraConfig.class);
@Autowired
private Environment environment;
@Bean
@Override
public CassandraClusterFactoryBean cluster() {
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
try {
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 10);
poolingOptions.setPoolTimeoutMillis(5000);
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 10);
// InputStream is = new FileInputStream(environment.getProperty("cassandra.truststore.path"));
InputStream is = new FileInputStream("D:/SampleProjects/spring-samples-master/restapi-cassandra/src/main/resources/cassandra_truststore.jks");
KeyStore keystore = KeyStore.getInstance(environment.getProperty("cassandra.truststore.type"));
System.out.println(environment.getProperty("cassandra.truststore.password"));
char[] pwd = environment.getProperty("cassandra.truststore.password").toCharArray();
keystore.load(is, pwd);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keystore);
TrustManager[] tm = tmf.getTrustManagers();
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tm, null);
JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslContext).build();
cluster.setUsername(environment.getProperty("cassandra.username"));
cluster.setPassword(environment.getProperty("cassandra.password"));
cluster.setContactPoints(environment.getProperty("cassandra.contactpoints"));
cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port")));
cluster.setSslEnabled(true);
cluster.setSslOptions(sslOptions);
cluster.setPoolingOptions(poolingOptions);
}
catch(Exception ex) {
System.out.println(ex);
}
return cluster;
}
@Override
protected String getKeyspaceName() {
return environment.getProperty("cassandra.keyspace");
}
@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
return new BasicCassandraMappingContext();
}
}
实体类
@AllArgsConstructor
@Getter @Setter
@Table
public class Employee {
@PrimaryKey
private @NonNull String id;
private @NonNull String firstName;
private @NonNull String lastName;
private @NonNull String email;
}
Repository class
package com.example.demo.repository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.model.Employee;
@Repository
public interface EmployeeRepository extends CrudRepository<Employee, String> {
}
控制器类
@RestController
public class EmployeeController
{
@Autowired
EmployeeRepository employeeRepository;
@GetMapping(value = "/healthcheck", produces = "application/json; charset=utf-8")
public String getHealthCheck()
{
return "{ \"isWorking\" : true }";
}
@GetMapping("/employees")
public List<Employee> getEmployees()
{
Iterable<Employee> result = employeeRepository.findAll();
List<Employee> employeesList = new ArrayList<Employee>();
result.forEach(employeesList::add);
return employeesList;
}
@GetMapping("/employee/{id}")
public Optional<Employee> getEmployee(@PathVariable String id)
{
Optional<Employee> emp = employeeRepository.findById(id);
return emp;
}
@PutMapping("/employee/{id}")
public Optional<Employee> updateEmployee(@RequestBody Employee newEmployee, @PathVariable String id)
{
Optional<Employee> optionalEmp = employeeRepository.findById(id);
if (optionalEmp.isPresent()) {
Employee emp = optionalEmp.get();
emp.setFirstName(newEmployee.getFirstName());
emp.setLastName(newEmployee.getLastName());
emp.setEmail(newEmployee.getEmail());
employeeRepository.save(emp);
}
return optionalEmp;
}
@DeleteMapping(value = "/employee/{id}", produces = "application/json; charset=utf-8")
public String deleteEmployee(@PathVariable String id) {
Boolean result = employeeRepository.existsById(id);
employeeRepository.deleteById(id);
return "{ \"success\" : "+ (result ? "true" : "false") +" }";
}
@PostMapping("/employee")
public Employee addEmployee(@RequestBody Employee newEmployee)
{
String id = String.valueOf(new Random().nextInt());
Employee emp = new Employee(id, newEmployee.getFirstName(), newEmployee.getLastName(), newEmployee.getEmail());
employeeRepository.save(emp);
return emp;
}
}
主类
@SpringBootApplication
@ComponentScan
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
我无法连接到亚马逊密钥空间,得到错误
原因:java.lang.IllegalArgumentException:未能添加联系人:cassandra.us-east-1.amazonaws。com.datastax.driver.core.Cluster$Builder.addContactPoint(Cluster.java:922)~[cassandra-driver-core-3.6.0.jar:na]com.datatax.drive.core.Cluster$Builder.addContactPoints(Cluster.java:942)~[cassandra-driver-core-2.6.jar:na]org.springframework.data.cassandras.config.CassandraClusterFactoryBean.afterPropertiesSet(CassandraClusterFactoryBean.java:174)~[spring-data-cassandra-2.1.4.RELEASE.jar:2.1-4.relase]位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractautoWireCapbleBeanFactory.java:1804)~[spring-beans-5.1.1.4release.jar:5.1.4.RELEASE],位于org.springframework.beans.factory.support.AbtractAutoWirecapableBean factory.initializeBean(Abstract AutoWirecableBeanFactory.java:1741)~[spring-beans-5.1.4.RELEASE.jar:5.1-4.relase]…由于java.net而省略了111个公共框架。未知后例外:cassandra.us-east-1.amazonaws.com
任何想法请分享。
尝试将本地DC设置为us-east-1。我在您的配置中没有看到它。
我能够从EC2实例连接到VPC中的ElastiCache Redis实例。但我想知道是否有办法连接到Amazon EC2实例之外的ElastiCache Redis节点,例如从我的本地开发设置或其他供应商提供的VPS实例。 当前在我的本地设置中尝试时: 我只在一段时间后才会暂停。
好的,我在 AWS 中创建一个实例,并遵循手册、视频等中的所有要点。但是我收到“无法连接到服务器,因为防火墙,关闭等” 我配置了以下内容: 实例: 私有IP OK 状态:正在运行 检查:一切正常 公共DNS:好的 公共ip:好的 弹性IP附加:好的 已连接网络接口(并且该网络具有安全组、ips等) 安全组(非默认): 入境的 类型协议端口范围源 RDP TCP 3389 0.0.0.0/0 固态混
我试图将我的spring应用程序连接到debezium/kafka:0.10,但没有成功。最初应用程序使用Wurstmeister/kafka图像,但现在我引入了debezium的一个新功能,并且希望两者只使用一个kafka图像。我不能把应用程序连接到debezium kafka或debezium连接到wurstmeister kafka。有人知道这两个图像是否都可以使用一个图像?欢迎任何想法:)
我已按照此处描述的所有步骤操作,当我运行 exec 命令时,我看到了以下角色: 但我的容器仍然无法加载: 原因:com . amazonaws . sdkclientexception:无法从链中的任何提供程序加载aws凭据:[EnvironmentVariableCredentialsProvider:无法从环境变量(AWS_ACCESS_KEY_ID(或AWS_ACCESS_KEY)和AWS_
试图做一些非常简单的事情,但不确定为什么它不起作用。 我下载了SQL workbench并连接到我的红移驱动程序。连接很好。我使用 现在我正试图连接到数据库。我尝试了和,但出现以下错误: 有人知道为什么没有连接吗?
我读过一些帖子,说亚马逊应用程序使用webviews相当多 (来源:https://www.quora.com/why-does-the-Amazon-app-use-webview-in-and-ios-application和https://www.teamblind.com/post/Amazon-app-webviews-cut4sn6c) 现在,我曾经在android中玩过webview