今天遇到需要连接SQLSERVER的需求,不过改配置后发现出现异常。
先贴dao.js的代码
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["custom/db.properties"]
}
},
dataSource : {
type:"org.apache.commons.dbcp.BasicDataSource",
events : {
depose : 'close'
},
fields : {
driverClassName : {java:"$conf.get('db.driverClassName')"},
url : {java:"$conf.get('db.url')"},
username : {java:"$conf.get('db.username')"},
password : {java:"$conf.get('db.password')"},
testWhileIdle : true,
maxActive : {java:"$conf.get('db.maxActive')"}
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource"}]
}
};
然后是db.propertity的代码
db.url=jdbc:sqlserver://1.1.1.1\SQL2008,49217:1433;databaseName=HY_Demo
db.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.username=zl
db.password=zl
db.maxActive=200
以下是启动时的报错日志
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: Fail to born 'org.nutz.dao.impl.NutDao'
by args: [
@(org.apache.commons.dbcp.BasicDataSource@3125f499)] becasue:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。) FAIL to create Ioc Bean name=[dao]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
at org.nutz.lang.Mirror.born(Mirror.java:988)
at org.nutz.lang.Lang.wrapThrow(Lang.java:165)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
at org.nutz.mvc.ActionHandler.(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at com.chiefdom.authority.filter.MainNutFilter.init(MainNutFilter.java:22)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
```
也确认过帐号和密码通过工具能正常连接