我创建了一个新的jhipster项目,后端为cassandra, 但是在使用./mvnv启动应用程序时,我收到错误并且应用程序无法启动。
错误
[错误]无法执行目标org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:在项目castrol上运行(default-cli):运行时发生异常。 null:InvocationTargetException:使用名称' userService'创建bean时出错:注册自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.springframework.security.crypto.password.PasswordEncoder com.kpit.castrol.service.UserService.passwordEncoder;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' securityConfiguration'的注册:自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.springframework.security.core.userdetails.UserDetailsService com.kpit.castrol.config.SecurityConfiguration.userDetailsService;嵌套异常是org.springframework.beans.factory.BeanCreationException:使用name' userDetailsService'创建bean时出错:注册自动装配的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.kpit.castrol.repository.UserRepository com.kpit.castrol.security.UserDetailsService.userRepository;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为' userRepository'的init时出错:init方法的调用失败;嵌套异常是com.datastax.driver.core.exceptions.InvalidQueryException:unconfigured table user - > [帮助1]
我是否需要在cassandra中创建用户表。
例外:
2016-07-13 16:03:51.852 ERROR 15114 --- [ost-startStop-1] o.a.c.c.C. [Tomcat]。[localhost]。[/]:异常启动过滤器springSecurityFilterChain
org.springframework.beans.factory.BeanCreationException:创建名称为' org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration':自动连接依赖项的注入失败的错误;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor, java.util.List)抛出java.lang.Exception;嵌套异常是org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' securityConfiguration'的注册:自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.springframework.security.core.userdetails.UserDetailsService com.kpit.castrol.config.SecurityConfiguration.userDetailsService;嵌套异常是org.springframework.beans.factory.BeanCreationException:使用name' userDetailsService'创建bean时出错:注册自动装配的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.kpit.castrol.repository.UserRepository com.kpit.castrol.security.UserDetailsService.userRepository;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为' userRepository'的init时出错:init方法的调用失败;嵌套异常是com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060) 在org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326) 在org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235) 在org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199) 在org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) 在org.apache.catalina.core.ApplicationFilterConfig。(ApplicationFilterConfig.java:109) 在org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4658) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5277) 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1408) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1398) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745)
enter code here
/**
* Cassandra repository for the User entity.
*/
@Repository
public class UserRepository {
@Inject
private Session session;
private Mapper<User> mapper;
private PreparedStatement findAllStmt;
private PreparedStatement findOneByActivationKeyStmt;
private PreparedStatement findOneByResetKeyStmt;
private PreparedStatement insertByActivationKeyStmt;
private PreparedStatement insertByResetKeyStmt;
private PreparedStatement deleteByActivationKeyStmt;
private PreparedStatement deleteByResetKeyStmt;
private PreparedStatement findOneByLoginStmt;
private PreparedStatement insertByLoginStmt;
private PreparedStatement deleteByLoginStmt;
private PreparedStatement findOneByEmailStmt;
private PreparedStatement insertByEmailStmt;
private PreparedStatement deleteByEmailStmt;
@PostConstruct
public void init() {
mapper = new MappingManager(session).mapper(User.class);
findAllStmt = session.prepare("SELECT * FROM user");
findOneByActivationKeyStmt = session.prepare(
"SELECT id " +
"FROM user_by_activation_key " +
"WHERE activation_key = :activation_key");
findOneByResetKeyStmt = session.prepare(
"SELECT id " +
"FROM user_by_reset_key " +
"WHERE reset_key = :reset_key");
insertByActivationKeyStmt = session.prepare(
"INSERT INTO user_by_activation_key (activation_key, id) " +
"VALUES (:activation_key, :id)");
insertByResetKeyStmt = session.prepare(
"INSERT INTO user_by_reset_key (reset_key, id) " +
"VALUES (:reset_key, :id)");
deleteByActivationKeyStmt = session.prepare(
"DELETE FROM user_by_activation_key " +
"WHERE activation_key = :activation_key");
deleteByResetKeyStmt = session.prepare(
"DELETE FROM user_by_reset_key " +
"WHERE reset_key = :reset_key");
findOneByLoginStmt = session.prepare(
"SELECT id " +
"FROM user_by_login " +
"WHERE login = :login");
insertByLoginStmt = session.prepare(
"INSERT INTO user_by_login (login, id) " +
"VALUES (:login, :id)");
deleteByLoginStmt = session.prepare(
"DELETE FROM user_by_login " +
"WHERE login = :login");
findOneByEmailStmt = session.prepare(
"SELECT id " +
"FROM user_by_email " +
"WHERE email = :email");
insertByEmailStmt = session.prepare(
"INSERT INTO user_by_email (email, id) " +
"VALUES (:email, :id)");
deleteByEmailStmt = session.prepare(
"DELETE FROM user_by_email " +
"WHERE email = :email");
}
public User findOne(String id) {
return mapper.get(id);
}
public Optional<User> findOneById(String id) {
return Optional.of(findOne(id));
}
public Optional<User> findOneByActivationKey(String activationKey) {
BoundStatement stmt = findOneByActivationKeyStmt.bind();
stmt.setString("activation_key", activationKey);
return findOneFromIndex(stmt);
}
public Optional<User> findOneByResetKey(String resetKey) {
BoundStatement stmt = findOneByResetKeyStmt.bind();
stmt.setString("reset_key", resetKey);
return findOneFromIndex(stmt);
}
public Optional<User> findOneByEmail(String email) {
BoundStatement stmt = findOneByEmailStmt.bind();
stmt.setString("email", email);
return findOneFromIndex(stmt);
}
public Optional<User> findOneByLogin(String login) {
BoundStatement stmt = findOneByLoginStmt.bind();
stmt.setString("login", login);
return findOneFromIndex(stmt);
}
public List<User> findAll() {
return mapper.map(session.execute(findAllStmt.bind())).all();
}
public User save(User user) {
User oldUser = mapper.get(user.getId());
if (oldUser != null) {
if (!StringUtils.isEmpty(oldUser.getActivationKey()) && !oldUser.getActivationKey().equals(user.getActivationKey())) {
session.execute(deleteByActivationKeyStmt.bind().setString("activation_key", oldUser.getActivationKey()));
}
if (!StringUtils.isEmpty(oldUser.getResetKey()) && !oldUser.getResetKey().equals(user.getResetKey())) {
session.execute(deleteByResetKeyStmt.bind().setString("reset_key", oldUser.getResetKey()));
}
if (!StringUtils.isEmpty(oldUser.getLogin()) && !oldUser.getLogin().equals(user.getLogin())) {
session.execute(deleteByLoginStmt.bind().setString("login", oldUser.getLogin()));
}
if (!StringUtils.isEmpty(oldUser.getEmail()) && !oldUser.getEmail().equals(user.getEmail())) {
session.execute(deleteByEmailStmt.bind().setString("email", oldUser.getEmail()));
}
}
BatchStatement batch = new BatchStatement();
batch.add(mapper.saveQuery(user));
if (!StringUtils.isEmpty(user.getActivationKey())) {
batch.add(insertByActivationKeyStmt.bind()
.setString("activation_key", user.getActivationKey())
.setString("id", user.getId()));
}
if (!StringUtils.isEmpty(user.getResetKey())) {
batch.add(insertByResetKeyStmt.bind()
.setString("reset_key", user.getResetKey())
.setString("id", user.getId()));
}
batch.add(insertByLoginStmt.bind()
.setString("login", user.getLogin())
.setString("id", user.getId()));
batch.add(insertByEmailStmt.bind()
.setString("email", user.getEmail())
.setString("id", user.getId()));
session.execute(batch);
return user;
}
public void delete(User user) {
BatchStatement batch = new BatchStatement();
batch.add(mapper.deleteQuery(user));
if (!StringUtils.isEmpty(user.getActivationKey())) {
batch.add(deleteByActivationKeyStmt.bind().setString("activation_key", user.getActivationKey()));
}
if (!StringUtils.isEmpty(user.getResetKey())) {
batch.add(deleteByResetKeyStmt.bind().setString("reset_key", user.getResetKey()));
}
batch.add(deleteByLoginStmt.bind().setString("login", user.getLogin()));
batch.add(deleteByEmailStmt.bind().setString("email", user.getEmail()));
session.execute(batch);
}
private Optional<User> findOneFromIndex(BoundStatement stmt) {
ResultSet rs = session.execute(stmt);
if (rs.isExhausted()) {
return Optional.empty();
}
return Optional.ofNullable(rs.one().getString("id"))
.map(id -> Optional.ofNullable(mapper.get(id)))
.get();
}
}