springboot 学习

来源:互联网 发布:资源商城源码 编辑:程序博客网 时间:2024/06/09 21:21

笔记:2017/8/30  
关于springboot项目打jar包  
1.指定    springboot启动类  
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.thunisoft.wszz.Application</start-class>

</properties>  



2.打包时,没有引进maven的jar包解决办法:    
加入如下配置:  
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>

</build>


3.java 调用python脚本

引用jar包

<dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<version>2.5.3</version>
</dependency>

编写java代码

PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("E:/add.py");
        PyFunction func = (PyFunction) interpreter.get("adder", PyFunction.class);
        int a = 2010, b = 6;
        PyObject pyobj = func.__call__(new PyInteger(a), new PyInteger(b));
        System.out.println("anwser = " + pyobj.toString());

python脚本:

add.py

def adder(a, b):    
   return a + b   


4.springboot定时任务

@Configuration
@EnableScheduling
public class SchedulingConfig {
    @Scheduled(cron = "0/10 * * * * ?")
    // 每20秒执行一次
    public void scheduler() {
        System.out.println("定时任务在跑啦。。。。。。。。。。。。。");
    }
}



原创粉丝点击