小编Mar*_*rek的帖子

spring boot autoconfiguration with jdbc template autowiring dataSource issue

我是Spring和J2EE的新手.我在使用带有Spring Boot自动配置的JDBC模板时遇到了麻烦.

我做的是我采用这里提供的RESTful Web服务的例子, 并决定扩展它以使用JDBC模板关系数据库访问.不幸的是,提供的另一个例子没有用,因为不考虑从xml beans文件提供dataSource的唯一困难.

我试图解决这个问题:

  1. 使用DAO Impl类作为Spring的不同实现的扩展.
  2. 添加到bean文件.
  3. 使用不同的DataSource类(例如DriverManagerDataSource).
  4. 试图在另一个类中自动装配一个简单的属性(比数据源更复杂的东西).
  5. 在开始时我刚刚编写了DAO类,但是后来我可能只有在实现了接口时才可以自动装配数据源,尝试它,没有帮助.

我尝试了在Stack或Google上找到的所有内容.大多数示例都严重过时或未得到答复,或与Spring Boot Autoconfiguration等无关.

我不断得到Property 'dataSource' is required错误,经过努力,如果最终设法将application-config.xml文件与bean 链接,但无法设法为JDBC的数据源自动装配.

我绝望地完成它并严重阻止,出于想法,如果有人可以提供最新的示例与Spring Boot自动配置,XML中的bean查找,JDBC的自动装配数据源,我会很高兴.

或者至少是一些想法,线索,甚至是如何寻找它,因为我甚至没有谷歌的关键词.

谢谢!

在此输入图像描述

Spring Application类.

package ws;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ComponentScan
@ImportResource("classpath:spring/application-config.xml")
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

Web服务类.

package ws;

import dao.UserDAOImpl;
import model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public …
Run Code Online (Sandbox Code Playgroud)

spring datasource jdbc autowired spring-boot

15
推荐指数
1
解决办法
5万
查看次数

无法使用Gradle和Spring Boot加载驱动程序类:com.mysql.jdbc.Driver

我的问题如下.我正在学习如何使用JDBC,Gradle和Spring框架(我对这些主题不熟悉).我一直试图用一个区别来实现以下示例,MySQL数据库而不是PostgreSQL.

就像我在标题中指定的那样,我的应用程序以跟随错误Cannot load driver class: com.mysql.jdbc.Driver(帖子末尾的堆栈跟踪)结束.

当然我在发布这个问题之前一直在谷歌搜索和阅读,我发现com.mysql.jdbc.Driver应该在程序中使用加载器加载,或者也可以使用Gradle构建脚本来完成.

我的问题如下:

  1. 为什么作者示例在没有加载器的情况下工作(在构建脚本的程序中)
  2. 如果加载器是绝对必要的,你能简单解释一下如何实现它吗?

我修改过的build.gradle文件:

buildscript { 
    repositories { 
        maven { url "http://repo.spring.io/libs-snapshot" } 
    } 
    dependencies { 
        classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6") 
        classpath 'mysql:mysql-connector-java:5.1.34'  
    } 
} 

apply plugin: "java" 
apply plugin: "spring-boot" 

buildDir = "out" 

jar { 
    baseName = "sb-jdbc" 
    version = "0.1" 
} 

repositories { 
    mavenCentral() 
    maven { url "http://repo.spring.io/libs-snapshot" } 
} 

dependencies { 
    def springBootVersion = '1.0.0.RC1'
    compile("org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion")
    compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
    compile("mysql:mysql-connector-java:5.1.34")

    testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
    testCompile("junit:junit:4.11")
} 
Run Code Online (Sandbox Code Playgroud)

我的application.properties档案:

spring.datasource.driverClassName=com.mysql.jdbc.Driver …
Run Code Online (Sandbox Code Playgroud)

mysql spring jdbc gradle spring-boot

7
推荐指数
2
解决办法
3万
查看次数

如何将文字 1 作为 Maybe Integer 返回?

我正在学习 Haskell,但无法将字面值返回1Maybe Integer

\n
alwaysOne:: Integer -> Maybe Integer\nalwaysOne n = 1\n
Run Code Online (Sandbox Code Playgroud)\n

提高

\n
error:\n    \xe2\x80\xa2 No instance for (Num (Maybe Integer))\n        arising from the literal \xe2\x80\x981\xe2\x80\x99\n    \xe2\x80\xa2 In the expression: 1\n      In an equation for \xe2\x80\x98alwaysOne\xe2\x80\x99: alwaysOne n = 1\n   |\n14 | alwaysOne n = 1\n   |             ^\n
Run Code Online (Sandbox Code Playgroud)\n

haskell

2
推荐指数
1
解决办法
104
查看次数

标签 统计

jdbc ×2

spring ×2

spring-boot ×2

autowired ×1

datasource ×1

gradle ×1

haskell ×1

mysql ×1