mysql - Gradle 无法识别 mysql 依赖项

标签 mysql spring spring-mvc gradle

我正在尝试从内存数据库中的 H2 迁移到 mysql,并在删除 H2 后将 compile("mysql:mysql-connector-java:5.1.6") 合并到我的 build.gradle 中依赖性。我还将以下内容放入我的 application.properties 中:

spring.datasource.url=jdbc:mysql://localhost:3306/mutibodb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto: create

但是,当我重建时,我收到此错误:http://pastebin.com/4cS9Dk0U 如果我不添加 mysql 或 h2 依赖项,这与我得到的错误相同,这意味着它根本不接受它。

我使用 H2 数据库的完整现有代码在这里:https://github.com/devdeep1987/MutiboProject/tree/master/MutiboServer

您能告诉我是否有遗漏的步骤吗?

更新: 我的 CustomUserDetailsS​​ervice 类如下:

@Service
public class CustomUserDetailsService implements UserDetailsService {
private UserRepository repository;

private static final Logger logger = LoggerFactory.getLogger(CustomUserDetailsService.class);
@Autowired
public CustomUserDetailsService(UserRepository repo) {
    this.repository = repo;
}

@Override
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
    logger.info("username:"+name);

    User u = repository.findByUsername(name);
    if (u == null)
        throw new UsernameNotFoundException("User details not found with this username: " + name);
    String username = u.getUsername();
    String password = u.getPassword();
    List authList = new ArrayList();
    authList.add(new SimpleGrantedAuthority("USER"));

    //get the encoded password
    //String encodedPassword = passwordEncoder.encode(password);

    org.springframework.security.core.userdetails.User user = new org.springframework.security.core.userdetails.User(username, password, authList);

    return user;
}

public boolean createUser(String username, String password) {
    User existing = repository.findByUsername(username);
    if(existing!=null)
        return false;
    User u = new User();
    u.setUsername(username);
    u.setPassword(password);

    repository.save(u);
    return true;
}

private List getAuthorities(String role) {
    List authList = new ArrayList();
    authList.add(new SimpleGrantedAuthority("USER"));

    //you can also add different roles here
    //for example, the user is also an admin of the site, then you can add ROLE_ADMIN
    //so that he can view pages that are ROLE_ADMIN specific
    if (role != null && role.trim().length() > 0) {
        if (role.equals("admin")) {
            authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
        }
    }

    return authList;
}
}

我的 UserRepository 类是:

@Repository
public interface UserRepository extends CrudRepository<User, Long>{

User findByUsername(String username);
}

最佳答案

将 spring-boot-gradle-plugin 的版本从 1.0.2.RELEASE 更改为 1.1.4.RELEASE 可以修复此问题。但不知道为什么。

关于mysql - Gradle 无法识别 mysql 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28019496/

相关文章:

php - 如何根据 PHP 中的 session 数据将用户重定向到不同的页面?

mysql - 获取一张 table 售出的门票总数。 rails

MySql 如何获取聊天记录显示在聊天列表中

java - Spring Security 根据入参标准进行授权

java - 尝试读取 WEB-INF 中的属性文件时 InputStream 为空

php - 将数据添加到json中

java - Spring : order of <map> tag

java - Spring Rest 中带有 JSON 的多部分不起作用

java - Spring MVC 中的语言环境

java - Controller 和方法上的 requestMapping 之间的区别是什么