diff --git a/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java b/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java index dd7d4375..ed592a98 100644 --- a/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java +++ b/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java @@ -27,7 +27,7 @@ public static void main(String[] args) { // 然后退出main线程 } - private static int sum() { + static int sum() { return fibo(36); } diff --git a/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java b/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java new file mode 100644 index 00000000..62c05ae3 --- /dev/null +++ b/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java @@ -0,0 +1,217 @@ +package java0.conc0303; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Supplier; + +public class HomeworkDemo1 { + public static void main(String[] args) { + +// long start = System.currentTimeMillis(); +// // 在这里创建一个线程或线程池, +// // 异步执行 下面方法 +// +// int result = sum(); //这是得到的返回值 +// +// // 确保 拿到result 并输出 +// System.out.println("异步计算结果为:" + result); +// +// System.out.println("使用时间:" + (System.currentTimeMillis() - start) + " ms"); +// +// // 然后退出main线程 + run(bySleep, "bySleep"); + + run(byJoin, "byJoin"); + + run(byCAS, "byCAS"); + + run(byLock, "byLock"); + + run(byObjectNotify, "byObjectNotify"); + + run(byCountDownLatch, "byCountDownLatch"); + + run(byFuture, "byFuture"); + + run(byFutureTask, "byFutureTask"); + + run(byCompletableFuture, "byCompletableFuture"); + } + + public static void run(Supplier supplier, String type) { + System.out.println(type); + long start = System.currentTimeMillis(); + // 在这里创建一个线程或线程池, + // 异步执行 下面方法 + // 这是得到的返回值 + int result = supplier.get(); + + // 确保 拿到result 并输出 + System.out.print("异步计算结果为:" + result + " "); + + System.out.println("使用时间:" + (System.currentTimeMillis() - start) + " ms"); + + // 然后退出main线程 + } + + private static int sum() { + return fibo(36); + } + + private static int fibo(int a) { + if (a < 2) { + return 1; + } + return fibo(a - 1) + fibo(a - 2); + } + + private static final Supplier bySleep = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> result.set(sum())); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result.get(); + }; + + private static final Supplier byJoin = () -> { + AtomicInteger result = new AtomicInteger(); + Thread thread = new Thread(() -> result.set(sum())); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return result.get(); + }; + + public static final Supplier byCAS = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + AtomicBoolean isDone = new AtomicBoolean(false); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> { + result.set(sum()); + isDone.set(true); + }); + while (!isDone.get()) { + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byLock = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Lock lock = new ReentrantLock(); + Condition condition = lock.newCondition(); + AtomicInteger result = new AtomicInteger(); + AtomicBoolean isDone = new AtomicBoolean(false); + executorService.execute(() -> { + lock.lock(); + try { + result.set(sum()); + isDone.set(true); + condition.signalAll(); + } finally { + lock.unlock(); + } + }); + + lock.lock(); + try { + while (!isDone.get()) { + condition.await(); + } + condition.signalAll(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + lock.unlock(); + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byObjectNotify = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Object object = new Object(); + AtomicInteger result = new AtomicInteger(); + AtomicBoolean isDone = new AtomicBoolean(false); + executorService.execute(() -> { + synchronized (object) { + result.set(sum()); + isDone.set(true); + object.notifyAll(); + } + }); + + synchronized (object) { + while (!isDone.get()) { + try { + object.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byCountDownLatch = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> { + result.set(sum()); + countDownLatch.countDown(); + }); + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result.get(); + }; + + private static final Supplier byFuture = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Future future = executorService.submit(()->sum()); + Integer result = null; + try { + result = future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result; + }; + + private static final Supplier byFutureTask = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + FutureTask futureTask = new FutureTask<>(Homework03::sum); + executorService.submit(futureTask); + Integer result = null; + try { + result = futureTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result; + }; + + public static final Supplier byCompletableFuture = () -> { + CompletableFuture completableFuture = CompletableFuture.supplyAsync(Homework03::sum); + return completableFuture.join(); + }; +} diff --git a/04fx/jdbc-demo/pom.xml b/04fx/jdbc-demo/pom.xml new file mode 100644 index 00000000..58b0482e --- /dev/null +++ b/04fx/jdbc-demo/pom.xml @@ -0,0 +1,72 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.0.9.RELEASE + + + 4.0.0 + + jdbc-demo + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + + org.springframework + spring-jdbc + 5.1.10.RELEASE + + + + com.h2database + h2 + 1.4.197 + runtime + + + + mysql + mysql-connector-java + 5.1.42 + runtime + + + + org.springframework + spring-core + 5.1.10.RELEASE + + + org.springframework + spring-beans + 5.1.10.RELEASE + + + org.springframework + spring-context + 5.1.10.RELEASE + + + + + com.zaxxer + HikariCP + 3.4.5 + + + \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java new file mode 100644 index 00000000..3db0ea7f --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java @@ -0,0 +1,69 @@ +package com.jeekbang.jdbc; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 使用 JDBC 原生接口,实现数据库的增删改查操作 + */ +public class H2JdbcDemo { + public static void main(String[] args) throws ClassNotFoundException { + ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + jdbc(); + } + + public static void jdbc() { + String url = "jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"; + String username = "sa"; + String password = ""; + try { + final Connection connection = DriverManager.getConnection(url, username, password); + // 查询 + find(connection); + + // 新增 + String sql = "insert into student(name) values('测试')"; + update(connection, sql); + find(connection); + + // 修改 + sql = "update student set name='测试-修改' where name='测试'"; + update(connection, sql); + find(connection); + + // 删除 + sql = "delete from student where name='测试-修改'"; + update(connection, sql); + find(connection); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private static void find(Connection connection) throws SQLException { + final Statement statement = connection.createStatement(); + statement.execute("select * from student"); + final ResultSet resultSet = statement.getResultSet(); + List students = new ArrayList<>(); + while (resultSet.next()){ + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void update(Connection connection, String sql) throws SQLException { + final Statement statement = connection.createStatement(); + statement.executeUpdate(sql); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java new file mode 100644 index 00000000..18548d75 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java @@ -0,0 +1,89 @@ +package com.jeekbang.jdbc; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 使用事务,PrepareStatement 方式,批处理方式 + */ +public class H2JdbcDemo2 { + public static void main(String[] args) throws ClassNotFoundException { + ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + jdbc(); + } + + public static void jdbc() { + String url = "jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"; + String username = "sa"; + String password = ""; + try { + final Connection connection = DriverManager.getConnection(url, username, password); + // 查询 + find(connection); + + // 新增 + add(connection); + find(connection); + + // 修改 + update(connection); + find(connection); + + // 删除 + delete(connection); + find(connection); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private static void find(Connection connection) throws SQLException { + final PreparedStatement statement = connection.prepareStatement("select * from student"); + final ResultSet resultSet = statement.executeQuery(); + List students = new ArrayList<>(); + while (resultSet.next()) { + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void add(Connection connection) throws SQLException { + String sql = "insert into student(name) values(?)"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + + private static void update(Connection connection) throws SQLException { + String sql = "update student set name=? where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.setString(2, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + private static void delete(Connection connection) throws SQLException { + String sql = "delete from student where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.executeUpdate(); + connection.commit(); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java new file mode 100644 index 00000000..18601e02 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java @@ -0,0 +1,94 @@ +package com.jeekbang.jdbc; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 配置 Hikari 连接池 + */ +public class HikariDemo { + + public static DataSource hikariDataSource(){ + HikariDataSource hikariDataSource = new HikariDataSource(); + hikariDataSource.setDriverClassName("org.h2.Driver"); + hikariDataSource.setJdbcUrl("jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"); + hikariDataSource.setUsername("sa"); + hikariDataSource.setPassword(""); + + return hikariDataSource; + } + + + public static void main(String[] args) throws SQLException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + final DataSource dataSource = hikariDataSource(); + final Connection connection = dataSource.getConnection(); + // 查询 + find(connection); + + // 新增 + add(connection); + find(connection); + + // 修改 + update(connection); + find(connection); + + // 删除 + delete(connection); + find(connection); + } + + + + + private static void find(Connection connection) throws SQLException { + final PreparedStatement statement = connection.prepareStatement("select * from student"); + final ResultSet resultSet = statement.executeQuery(); + List students = new ArrayList<>(); + while (resultSet.next()) { + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void add(Connection connection) throws SQLException { + String sql = "insert into student(name) values(?)"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + + private static void update(Connection connection) throws SQLException { + String sql = "update student set name=? where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.setString(2, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + private static void delete(Connection connection) throws SQLException { + String sql = "delete from student where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.executeUpdate(); + connection.commit(); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java new file mode 100644 index 00000000..3fd87911 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java @@ -0,0 +1,84 @@ +package com.jeekbang.jdbc; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 配置 Hikari 连接池 + */ +public class MyDataSql { + static final String dbDriver = "com.mysql.jdbc.Driver"; + static final String url = "jdbc:mysql://localhost:3306/eplat?rewriteBatchedStatements=true"; + static final String username = "july"; + static final String password = "!QAZ2wsx"; + + + public static DataSource hikariDataSource() { + HikariDataSource hikariDataSource = new HikariDataSource(); + hikariDataSource.setDriverClassName(dbDriver); + hikariDataSource.setJdbcUrl(url); + hikariDataSource.setUsername(username); + hikariDataSource.setPassword(password); + + return hikariDataSource; + } + + + public static void main(String[] args) throws SQLException { + //数据库连接 + DataSource dataSource = hikariDataSource(); + Connection conn = dataSource.getConnection(); + + //订单数据 + long start=System.currentTimeMillis(); + createBigOrderData(conn,1000000); + System.out.println("生成100万条订单数据耗时:"+ (System.currentTimeMillis()-start) / 1000 + " s"); + + } + + /** + * 生成数据 + * @param conn + * @param count + */ + private static void createBigOrderData(Connection conn, int count) { + String sql = "insert into t_order(id,user_id,addr_id,goods_id,unit_price,quantity,amount,actice_id,snapshot_id,real_price,real_amount)" + + " values(?,?,?,?,?,?,?,?,?,?,?)"; + try { + PreparedStatement pst = conn.prepareStatement(sql); + int i=0; + while (i < count) { + for (int j=0; j<10000 && j + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql b/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql new file mode 100644 index 00000000..54fb77e8 --- /dev/null +++ b/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql @@ -0,0 +1,2 @@ +insert into student(name) values('张三'); +insert into student(name) values('李四'); \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql b/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql new file mode 100644 index 00000000..9ad88972 --- /dev/null +++ b/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql @@ -0,0 +1,8 @@ +-- h2-schame.sql +drop table if exists student ; + +-- 创建表 +create table student( + id int primary key auto_increment, + name varchar(20) +); \ No newline at end of file diff --git a/04fx/spring01/src/main/java/homework0902/0902.md b/04fx/spring01/src/main/java/homework0902/0902.md new file mode 100644 index 00000000..5c1fc1fb --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/0902.md @@ -0,0 +1 @@ +写代码实现Spring Bean的装配,方式越多越好(XML、Annotation都可以) \ No newline at end of file diff --git a/04fx/spring01/src/main/java/homework0902/Homework0902.java b/04fx/spring01/src/main/java/homework0902/Homework0902.java new file mode 100644 index 00000000..5819fe22 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/Homework0902.java @@ -0,0 +1,31 @@ +package homework0902; + +import homework0902.pojo.Student; +import homework0902.pojo.Student1; +import homework0902.pojo.Student2; +import homework0902.pojo.StuConfig; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Homework0902 { + public static void main(String[] args) { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("hwApplicationContext.xml"); + ApplicationContext configContext = new AnnotationConfigApplicationContext(StuConfig.class); + + Student student1 = (Student1) applicationContext.getBean("student1"); + System.out.println("方法1:" + student1.toString()); + + Student student2 = (Student2) applicationContext.getBean("student2"); + System.out.println("方法2:" + student2.toString()); + + Student student3 = applicationContext.getBean(Student2.class); + System.out.println("方法3:" + student3.toString()); + + Student student4 = (Student) configContext.getBean("stu1"); + System.out.println("方法4:" + student4.toString()); + + } + + +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java b/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java new file mode 100644 index 00000000..9e0fee4f --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java @@ -0,0 +1,13 @@ +package homework0902.pojo; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class StuConfig{ + @Bean(name = "stu1") + public Student getStudent() { + return new Student1(3,"xiyuan3"); + } + +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student.java b/04fx/spring01/src/main/java/homework0902/pojo/Student.java new file mode 100644 index 00000000..17d1bc97 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student.java @@ -0,0 +1,8 @@ +package homework0902.pojo; + + +import java.io.Serializable; + +public interface Student extends Serializable { + void dingdo(); +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student1.java b/04fx/spring01/src/main/java/homework0902/pojo/Student1.java new file mode 100644 index 00000000..3a4e8feb --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student1.java @@ -0,0 +1,21 @@ +package homework0902.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Student1 implements Student { + + private int id; + private String name; + + @Override + public void dingdo() { + System.out.println("Student1"); + } +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student2.java b/04fx/spring01/src/main/java/homework0902/pojo/Student2.java new file mode 100644 index 00000000..847dc745 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student2.java @@ -0,0 +1,25 @@ +package homework0902.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +@Component(value = "student2") +public class Student2 implements Student { + @Value("002") + private int id; + @Value("西元2") + private String name; + + @Override + public void dingdo() { + System.out.println("Student2"); + } +} diff --git a/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java b/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java index 1c09e4c5..bc3c7625 100644 --- a/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java +++ b/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java @@ -1,6 +1,7 @@ package io.kimmking.springjms; import io.kimmking.spring01.Student; +import org.apache.activemq.command.ActiveMQQueue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; @@ -14,9 +15,10 @@ public class SendService { @Autowired JmsTemplate jmsTemplate; - + @Autowired + ActiveMQQueue queue; public void send(final Student user) { - jmsTemplate.send("test.queue", new MessageCreator() { + jmsTemplate.send(queue, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createObjectMessage(user); diff --git a/04fx/spring01/src/main/resources/hwApplicationContext.xml b/04fx/spring01/src/main/resources/hwApplicationContext.xml new file mode 100644 index 00000000..43dc3e20 --- /dev/null +++ b/04fx/spring01/src/main/resources/hwApplicationContext.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/applicationContext.xml b/04fx/spring01/target/classes/applicationContext.xml new file mode 100644 index 00000000..985a106e --- /dev/null +++ b/04fx/spring01/target/classes/applicationContext.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/hwApplicationContext.xml b/04fx/spring01/target/classes/hwApplicationContext.xml new file mode 100644 index 00000000..d4e5ed13 --- /dev/null +++ b/04fx/spring01/target/classes/hwApplicationContext.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/log4j.xml b/04fx/spring01/target/classes/log4j.xml new file mode 100644 index 00000000..efc1f4f6 --- /dev/null +++ b/04fx/spring01/target/classes/log4j.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/springjms-receiver.xml b/04fx/spring01/target/classes/springjms-receiver.xml new file mode 100644 index 00000000..e0d9fbc6 --- /dev/null +++ b/04fx/spring01/target/classes/springjms-receiver.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/springjms-sender.xml b/04fx/spring01/target/classes/springjms-sender.xml new file mode 100644 index 00000000..119ec07a --- /dev/null +++ b/04fx/spring01/target/classes/springjms-sender.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/springboot01/pom.xml b/04fx/springboot01/pom.xml index 93d83574..810b8aba 100644 --- a/04fx/springboot01/pom.xml +++ b/04fx/springboot01/pom.xml @@ -43,7 +43,6 @@ org.springframework.boot spring-boot-starter-data-mongodb - org.springframework.boot diff --git a/04fx/springboot01/src/main/java/homework1003/1003.md b/04fx/springboot01/src/main/java/homework1003/1003.md new file mode 100644 index 00000000..2d9c3b48 --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/1003.md @@ -0,0 +1 @@ +给前面课程提供的 Student/Klass/School 实现自动配置和 Starter. \ No newline at end of file diff --git a/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java new file mode 100644 index 00000000..6390ceab --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java @@ -0,0 +1,12 @@ +package homework1003; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +@SpringBootApplication(scanBasePackages = {"homework1003"}) +public class SpringBoot1003Application { + public static void main(String[] args) { + ConfigurableApplicationContext context =SpringApplication.run(SpringBoot1003Application.class, args); + } +} diff --git a/04fx/springboot01/src/main/java/homework1003/web/WebPage.java b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java new file mode 100644 index 00000000..5fa7f12b --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java @@ -0,0 +1,24 @@ +package homework1003.web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class WebPage { + + @RequestMapping("/test") + @ResponseBody + public String hello() { + return "hello SpringBoot"; + } + + @RequestMapping("/myStarter") + @ResponseBody + public String xiyuan() { + + return ""; + } +} diff --git a/04fx/springboot01/src/main/resources/application.yml b/04fx/springboot01/src/main/resources/application.yml index fa5370a3..7db96b12 100644 --- a/04fx/springboot01/src/main/resources/application.yml +++ b/04fx/springboot01/src/main/resources/application.yml @@ -1,5 +1,10 @@ server: - port: 8080 + port: 8081 + +diy: + stu: + id: 1 + name: xiyuan spring: activemq: diff --git a/04fx/springboot01/target/classes/application.yml b/04fx/springboot01/target/classes/application.yml new file mode 100644 index 00000000..7db96b12 --- /dev/null +++ b/04fx/springboot01/target/classes/application.yml @@ -0,0 +1,64 @@ +server: + port: 8081 + +diy: + stu: + id: 1 + name: xiyuan + +spring: + activemq: + broker-url: tcp://127.0.0.1:61616 + user: admin + password: admin + close-timeout: 15s # 在考虑结束之前等待的时间 + in-memory: true # 默认代理URL是否应该在内存中。如果指定了显式代理,则忽略此值。 + non-blocking-redelivery: false # 是否在回滚回滚消息之前停止消息传递。这意味着当启用此命令时,消息顺序不会被保留。 + send-timeout: 0 # 等待消息发送响应的时间。设置为0等待永远。 + queue-name: active.queue + topic-name: active.topic.name.model + packages: + trust-all: true #不配置此项,会报错 + pool: + enabled: true + max-connections: 10 #连接池最大连接数 + idle-timeout: 30000 #空闲的连接过期时间,默认为30秒 + + + + data: + mongodb: + uri: mongodb://localhost:27017/mydb + + profiles: + active: true + +# jms: +# pub-sub-domain: true #默认情况下activemq提供的是queue模式,若要使用topic模式需要配置下面配置 + +# 是否信任所有包 +#spring.activemq.packages.trust-all= +# 要信任的特定包的逗号分隔列表(当不信任所有包时) +#spring.activemq.packages.trusted= +# 当连接请求和池满时是否阻塞。设置false会抛“JMSException异常”。 +#spring.activemq.pool.block-if-full=true +# 如果池仍然满,则在抛出异常前阻塞时间。 +#spring.activemq.pool.block-if-full-timeout=-1ms +# 是否在启动时创建连接。可以在启动时用于加热池。 +#spring.activemq.pool.create-connection-on-startup=true +# 是否用Pooledconnectionfactory代替普通的ConnectionFactory。 +#spring.activemq.pool.enabled=false +# 连接过期超时。 +#spring.activemq.pool.expiry-timeout=0ms +# 连接空闲超时 +#spring.activemq.pool.idle-timeout=30s +# 连接池最大连接数 +#spring.activemq.pool.max-connections=1 +# 每个连接的有效会话的最大数目。 +#spring.activemq.pool.maximum-active-session-per-connection=500 +# 当有"JMSException"时尝试重新连接 +#spring.activemq.pool.reconnect-on-exception=true +# 在空闲连接清除线程之间运行的时间。当为负数时,没有空闲连接驱逐线程运行。 +#spring.activemq.pool.time-between-expiration-check=-1ms +# 是否只使用一个MessageProducer +#spring.activemq.pool.use-anonymous-producers=true \ No newline at end of file