浏览代码

完善配置,使用自动配置。

周浩 9 年之前
父节点
当前提交
76424956a7

+ 24 - 0
hsweb-web-run/src/main/java/org/hsweb/web/boot/Run.java

@@ -0,0 +1,24 @@
+package org.hsweb.web.boot;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.web.servlet.support.RequestContext;
+
+/**
+ * Created by 浩 on 2016-01-16 0016.
+ */
+@Configuration
+@EnableAutoConfiguration
+@ComponentScan(basePackages = {"org.hsweb.web"})
+@MapperScan(basePackages = {"org.hsweb.web.dao"})
+@EnableTransactionManagement(proxyTargetClass = true)
+public class Run {
+    public static void main(String[] args) {
+        SpringApplication.run(Run.class,args);
+    }
+}

+ 40 - 0
hsweb-web-run/src/main/resources/application.yml

@@ -0,0 +1,40 @@
+#LOGGING
+logging:
+    config: classpath:config/logback.xml
+
+server:
+    port: 8088
+spring:
+    application:
+        name: ${app.name}
+        index: index.html
+        version: ${app.version}
+    datasource:
+        name: core
+        url: ${jdbc.url}
+        driverClassName: ${jdbc.driverClassName}
+        username: ${jdbc.username}
+        password: ${jdbc.password}
+        type: com.alibaba.druid.pool.DruidDataSource
+        filters: stat
+        maxActive: 20
+        initialSize: 1
+        maxWait: 60000
+        minIdle: 1
+        timeBetweenEvictionRunsMillis: 60000
+        minEvictableIdleTimeMillis: 300000
+        validationQuery: select 'x'
+        testWhileIdle: true
+        testOnBorrow: false
+        testOnReturn: false
+        poolPreparedStatements: true
+        maxOpenPreparedStatements: 20
+    freemarker :
+                suffix : .ftl
+                request-context-attribute : request
+                expose-request-attributes : true
+# MyBatis
+mybatis:
+    type-aliases-package: org.hsweb.web.bean.po
+    mapper-locations: classpath*:org/hsweb/web/dao/impl/mybatis/mapper/oracle/**/*.xml
+    config: classpath:config/mybatis-config.xml

+ 3 - 0
hsweb-web-run/src/main/resources/banner.txt

@@ -0,0 +1,3 @@
+${AnsiColor.YELLOW}------------------------------------------------------
+${AnsiColor.YELLOW}:: Running ${AnsiColor.RED}${app.name} ${AnsiColor.YELLOW}(${app.version})
+${AnsiColor.YELLOW}-------------------------------------------------------${AnsiColor.WHITE}

+ 16 - 0
hsweb-web-run/src/main/resources/config/logback.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <!-- 控制台输出日志 -->
+    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} > %-5level %logger{35} - %m%n</pattern>
+        </encoder>
+    </appender>
+    <logger name="org.springframework" level="ERROR" />
+    <logger name="org.springframework.web" level="DEBUG" />
+    <logger name="org.apache.tomcat" level="ERROR" />
+    <logger name="org.hsweb" level="DEBUG" />
+    <root level="ERROR">
+        <appender-ref ref="Console"/>
+    </root>
+</configuration>

+ 2 - 1
hsweb-web-test/src/main/resources/mybatis-config.xml

@@ -48,6 +48,7 @@
 
         <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->
         <setting name="aggressiveLazyLoading" value="false"/>
-
+        <setting name="proxyFactory" value="CGLIB"/>
     </settings>
+
 </configuration>

+ 1 - 0
hsweb-web-run/src/main/resources/static/1.txt

@@ -0,0 +1 @@
+test2

+ 1 - 0
hsweb-web-run/src/main/resources/templates/1.ftl

@@ -0,0 +1 @@
+hello

+ 1 - 0
hsweb-web-run/src/main/resources/templates/error.ftl

@@ -0,0 +1 @@
+${status}:${error}</br>