SpringBoot配置

1.ServerApplication

  

package com.ysotek.wms.microservice.infrastructure.application;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan(basePackages = {"com.ysotek.wms.microservice.infrastructure"
        ,"com.ysotek.wms.microservice.core.application"
        ,"com.ysotek.wms.microservice.core.datasource"})
@MapperScan("com.ysotek.wms.microservice.infrastructure.mapper")
@ImportResource(locations={"classpath:application-bean.xml"})
public class ServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);
    }
}

2.application-bean.xml

  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <bean id="defaultDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://218.244.146.200:3306/yl_dev?useUnicode=true&characterEncoding=utf-8" />
        <property name="username" value="lp_user" />
        <property name="password" value="ysolp123"/>
    </bean>

    <bean id="defaultTxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="defaultDataSource" />
    </bean>

    <bean id="dynamicDatasourceTransactionFactory" class="com.ysotek.wms.microservice.core.datasource.DynamicDatasourceSpringManagedTransactionFactory"/>

    <bean id="defaultSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="defaultDataSource"/>
        <property name="mapperLocations" value="classpath:mybatis/mapper/**/*.xml"/>
        <property name="transactionFactory" ref="dynamicDatasourceTransactionFactory"/>
    </bean>

</beans>

3.application.properties
 
spring.application.name=infrastructure-service
server.port=8765
#注册中心地址
eureka.client.serviceUrl.defaultZone=http://campus.wms.tnbchina.com:8761/eureka
eureka.instance.hostname=campus.wms.tnbchina.com

wms.config.env=dev

  
 
4.添加日志logback.xml
  
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="RemoteAppender" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>218.244.146.200:9250</destination>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <customFields>{"appname":"infrastructure-service","env":"demo"}</customFields>
        </encoder>
    </appender>
    <appender name="ConsoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>./InfrastructureServiceLogs/logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="INFO">
    </root>
    <logger name="InfoLogger" level="ALL" additivity="false">
        <!--<appender-ref ref="RemoteAppender"/>-->
        <appender-ref ref="ConsoleAppender"/>
        <appender-ref ref="FileAppender"/>
    </logger>
</configuration>

5.pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>WMS_MicroService</artifactId>
        <groupId>com.ysotek.wms.microservice</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>infrastructure</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.ysotek.wms.microservice</groupId>
            <artifactId>core-datasource</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.ysotek.wms.microservice</groupId>
            <artifactId>model</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值