我试图按照
的例子当我尝试创建一个新表
时 adminTemplate.createTable(true, CqlIdentifier.of("book"), Book.class, new HashMap<String, Object>());
我得到NullPointerException
java.lang.NullPointerException
at com.ibm.whi.breastadvisor.contoller.test.MyIntegrationTestClass.setUp(MyIntegrationTestClass.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
我做错了什么?
这是我在课程开头的内容
@Autowired
private CassandraAdminOperations adminTemplate;
public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS myKeyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };";
public static final String KEYSPACE_ACTIVATE_QUERY = "USE myKeyspace;";
我还需要其他什么吗?这是我的设置功能
try {
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
} catch (ConfigurationException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
throw e1;
} catch (TTransportException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
throw e1;
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
throw e1;
} catch (InterruptedException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
throw e1;
}
final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
logger.info("Server Started at 127.0.0.1:9142... ");
final Session session = cluster.connect();
session.execute(KEYSPACE_CREATION_QUERY);
session.execute(KEYSPACE_ACTIVATE_QUERY);
logger.info("KeySpace myKeyspace created and activated.");
Thread.sleep(5000);
try {
logger.info("Will try to create book table");
adminTemplate.createTable(true, CqlIdentifier.of("book"), Book.class, new HashMap<String, Object>());
logger.info("book table created");
} catch (NullPointerException e) {
logger.error("Could not create table", e);
throw e;
}