我是Spring和J2EE的新手.我在使用带有Spring Boot自动配置的JDBC模板时遇到了麻烦.
我做的是我采用这里提供的RESTful Web服务的例子, 并决定扩展它以使用JDBC模板关系数据库访问.不幸的是,提供的另一个例子没有用,因为不考虑从xml beans文件提供dataSource的唯一困难.
我尝试了在Stack或Google上找到的所有内容.大多数示例都严重过时或未得到答复,或与Spring Boot Autoconfiguration等无关.
我不断得到Property 'dataSource' is required错误,经过努力,如果最终设法将application-config.xml文件与bean 链接,但无法设法为JDBC的数据源自动装配.
我绝望地完成它并严重阻止,出于想法,如果有人可以提供最新的示例与Spring Boot自动配置,XML中的bean查找,JDBC的自动装配数据源,我会很高兴.
或者至少是一些想法,线索,甚至是如何寻找它,因为我甚至没有谷歌的关键词.
谢谢!

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)
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) 我的问题如下.我正在学习如何使用JDBC,Gradle和Spring框架(我对这些主题不熟悉).我一直试图用一个区别来实现以下示例,MySQL数据库而不是PostgreSQL.
就像我在标题中指定的那样,我的应用程序以跟随错误Cannot load driver class: com.mysql.jdbc.Driver(帖子末尾的堆栈跟踪)结束.
当然我在发布这个问题之前一直在谷歌搜索和阅读,我发现com.mysql.jdbc.Driver应该在程序中使用加载器加载,或者也可以使用Gradle构建脚本来完成.
我的问题如下:
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) 我正在学习 Haskell,但无法将字面值返回1为Maybe Integer
alwaysOne:: Integer -> Maybe Integer\nalwaysOne n = 1\nRun Code Online (Sandbox Code Playgroud)\n提高
\nerror:\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 | ^\nRun Code Online (Sandbox Code Playgroud)\n