可能存在的问题

log4j.jar包版本不对,不能加载自定义log4j.properties

使用druid配置sqlserver报错

注意@Inject注解引用的包名org.nutz.ioc.loader.annotation.Inject

代码

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>


<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

dao.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["config/custom/"]
}
},
dataSource : {
factory : "$conf#make",
args : ["com.alibaba.druid.pool.DruidDataSource", "db."],
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource"}]
},
sdataSource : {
type : "org.nutz.dao.impl.SimpleDataSource",
fields : {
jdbcUrl : 'jdbc:sqlserver://106.15.48.4:1433;DatabaseName=QPAccountsDB',
username : 'sa',
password : 'QZJSZmj20170120+'
}
},
sdao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"sdataSource"}]
}
};

db.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#mysql
db.name=
db.url=
db.username=
db.password=
db.validationQuery=select 1
db.maxActive=100
db.testWhileIdle=true
db.filters=mergeStat
db.connectionProperties=druid.stat.slowSqlMillis=2000
db.defaultAutoCommit=true

#sqlserver2008 use sqljdbc42.jar for jdk8
sdb.name=
sdb.url=
sdb.username=
sdb.password=

log4j.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
log4j.rootLogger=DEBUG,Console,Stdout

#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

log4j.appender.Stdout = org.apache.log4j.DailyRollingFileAppender
log4j.appender.Stdout.File = E://logs/qimage.log
log4j.appender.Stdout.Append = true
log4j.appender.Stdout.Threshold = DEBUG
log4j.appender.Stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

#log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=${catalina.base}/logs/nutzwk.log
#log4j.appender.file.DatePattern='.'yyyy-MM-dd'.log'
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=[%-5p] %d %l - %m%n