顯示具有 java 標籤的文章。 顯示所有文章
顯示具有 java 標籤的文章。 顯示所有文章

2017年3月25日 星期六

【Spring Boot】Why using spring boot

When I need to produce restful api using spring framework,I use Spring MVC4 ,that I need to config spring structure as below

We saw in project have some config file(xml),in spring xml config file was common usage for spring developer,everything look like well.
But in spring boot ,we don’t need config file anymore,and we don’t need to deploy web app to container.

Lets take a look what the spring boot project structure
Yes,no any config file,and no web.xml,amazing!

When we try to add to tomcat to test out project,ide can not let us add boot app to server

So how can we test out app?
Let's take a look on below file

DomoApplication.java



Lets run it as boot app


We can see this app running on 8080 port
Lets try it on browser,look like it running,but content a bit odd,actually we need to add something
We add some content in DomoApplication.java,and run it again
Looks good now



Spring boot let us drop config files,spring developer all know if our project became big or huge ,we always miss in config files so pain,spring boot let us more config again.

So here we got 2 nice feature
  1. No config anymore
  2. No need to install container before deploy to production server
Great~~~

In next post ,I will write more about why I like to use spring boot for my further java web development.see you~~




2014年9月24日 星期三

【Android】Add Jars into Android Studio Project

image

image

image

 

image

 

Android Studio will add you library to build.gradle script

image

2013年7月9日 星期二

【Spring】Test in Spring MVC3

   1: package com.lywebii.goldprice;
   2:  
   3: import static org.junit.Assert.*;
   4:  
   5: import java.util.List;
   6:  
   7: import org.junit.After;
   8: import org.junit.Before;
   9: import org.junit.Test;
  10: import org.junit.runner.RunWith;
  11: import org.springframework.beans.factory.annotation.Autowired;
  12: import org.springframework.data.mongodb.core.MongoTemplate;
  13: import org.springframework.data.mongodb.core.geo.Box;
  14: import org.springframework.data.mongodb.core.geo.Point;
  15: import org.springframework.data.mongodb.core.index.GeospatialIndex;
  16: import org.springframework.data.mongodb.core.query.Criteria;
  17: import org.springframework.data.mongodb.core.query.Order;
  18: import org.springframework.data.mongodb.core.query.Query;
  19: import org.springframework.test.context.ContextConfiguration;
  20: import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  21:  
  22: import com.lywebii.goldprice.model.Floating;
  23:  
  24: @RunWith(SpringJUnit4ClassRunner.class)
  25: @ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/root-context.xml"})
  26: public class TestFloatingController {
  27:     @Autowired
  28:     MongoTemplate mongoTemplate;
  29:     
  30:     @Before
  31:     public void setUp() throws Exception {
  32:         Floating floating = new Floating();
  33:         floating.setPosition(new double[]{25.0017035,121.5000121});//235台灣新北市中和區中和路37號
  34:         this.mongoTemplate.save(floating);
  35:         
  36:         floating = new Floating();
  37:         floating.setPosition(new double[]{25.0209304,121.4595818}); //220台灣新北市板橋區金華街90-140號
  38:         this.mongoTemplate.save(floating);
  39:         
  40:         floating = new Floating();
  41:         floating.setPosition(new double[]{25.0052171,121.4198273}); //238台灣新北市樹林區中正路214號
  42:         this.mongoTemplate.save(floating);
  43:         
  44:         floating = new Floating();
  45:         floating.setPosition(new double[]{22.6092776,120.316238}); //806台灣高雄市前鎮區南寧街
  46:         this.mongoTemplate.save(floating);
  47:     }
  48:  
  49:     @After
  50:     public void tearDown() throws Exception {
  51:         this.mongoTemplate.dropCollection(Floating.class);
  52:     }
  53:  
  54:     @Test
  55:     public void test() {
  56:         Query query = new Query();
  57:         query.sort().on("date", Order.DESCENDING);
  58:         
  59:  
  60:         this.mongoTemplate.indexOps(Floating.class).ensureIndex(new GeospatialIndex("position"));
  61:  
  62:  
  63:         List<Floating> list = this.mongoTemplate.find(new Query(Criteria.where("position").near(new Point(25.0052171,121.4198273)).maxDistance(5/111.12)),Floating.class);
  64:         System.out.println("Circle:"+list);
  65:  
  66:  
  67:         list = this.mongoTemplate.find(new Query(Criteria.where("position").within(new Box(new Point(0.2, 0.2), new Point(1, 1)))),Floating.class);
  68:         System.out.println("Box:"+list);
  69:  
  70:         
  71:     }
  72:  
  73: }

 


Above code was about usging monogdb template to save postion data and query near point that given.


IOC Configuration file using below code:



   1: @ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/root-context.xml"})

2013年4月23日 星期二

【Android】Check or go to spacified app

   1: String appPackage = "jp.naver.line.android";
   2: Intent intent = getPackageManager().getLaunchIntentForPackage(appPackage);
   3: if(intent!=null){
   4:     startActivity(intent);
   5: }else{
   6:     intent = new Intent(Intent.ACTION_VIEW);
   7:     intent.setData(Uri.parse("market://details?id="+appPackage));
   8: }
   9: startActivity(intent);

2012年5月10日 星期四

【Android】Using Google Maps note

  • Create project need to select 【Google APIs】

        image

  • AndroidManifest.xml need to add below tag

       image

2012年4月20日 星期五

【Java】 Convert a Hex String to an Integer and Back Again

Hex String to an Integer 

   1: String hex = "2A"; //The answer is 42  



   2: int intValue = Integer.parseInt(hex, 16);  






Integer to Hex String





   1: String hex = Integer.toHexString(42);  





2012年4月1日 星期日

【Android】add a layout file into current activity

If layout flie(e.g. layout.xml) need to add to acticity using hardcard,below code is ths example

  1: controlInflater = LayoutInflater.from(getBaseContext());
  2:         View viewControl = controlInflater.inflate(R.layout.control, null);
  3:         LayoutParams layoutParamsControl 
  4:             = new LayoutParams(LayoutParams.FILL_PARENT, 
  5:             LayoutParams.FILL_PARENT);
  6:         this.addContentView(viewControl, layoutParamsControl);

2012年3月28日 星期三

【Android】Development Note

General:

  1. AdMob 4.3.1 need to use bigger than Android 3.2 SDK
  2. android:adjustViewBounds="true" auto scale to all parent
  3. SDK can not find adb.exe,we sould add system enviroment path link to D:\Program Files\Android\android-sdk\platform-tools(platform-tools default not exist)first,and execute SDK Manager for downloading Platform-tools

R17:

  1. jar file need to put into a libs folder in project

Android 3.1出现 android.os.NetworkOnMainThreadException异常 

解决办法:

在onCreate方法中添加如下代码:

  1: public void onCreate() {  
  2:      StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()     
  3:             .detectDiskReads()     
  4:             .detectDiskWrites()     
  5:             .detectNetwork()   // or .detectAll() for all detectable problems     
  6:             .penaltyLog()     
  7:             .build());     
  8:      StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()     
  9:             .detectLeakedSqlLiteObjects()     
 10:             .detectLeakedClosableObjects()     
 11:             .penaltyLog()     
 12:             .penaltyDeath()     
 13:             .build());  
 14: } 

2012年3月27日 星期二

【Android】Bitmap export to file

    String tmpImg = "Leon456.png"; 
 
    OutputStream os = null; 
    try { 
      os = new FileOutputStream(loc + tmpImg); 
      bitmap.compress(CompressFormat.PNG, 100, os); 
    } catch(IOException e) { 
      Log.e("combineImages", "problem combining images", e); 
    }



   


2012年2月15日 星期三

Play Framework Study Regular Note

  1. 通過說明下載.zip隨意放個地方就可以了,個人就愛簡單,所以在mac下brew install play安裝及完成設定,不過在找安裝目錄時卻不知brew幫我裝到哪去,使用brew list play,好的,原來是在/usr/local/Cellar下,這點雖不算是play frame專有問題,還是記錄下來
  2. 在 1.2.3版中官方文件中說明Model使用delete是先用 findById後再叫該物件的delete,不過原始碼沒有找到沒有參數的delete方法,只有  public static int delete(String query, Object... params)可叫,源碼文件提到是使用HQL,HQL格式應該是 FROM table_name WHERE id = :id,不過我這邊試的應該是使用JDBC用法 FROM table_name WHERE id=?
  3. JPA model可使用jpagen的mudule,使用時必需在conf/application.conf 定義連線資訊 其中 db.driver db.url db.user db.pass 及jpgen.mode為必填
  4. dependencies.yml  增加時格式如下:

    require:
        - play
        - play->spring 1.0.2

    reference:http://www.playframework.org/documentation/1.2.4/dependency#format

    a.play 1.2.3在做precomile時,會告知現在建議放在  dependencies.yml 不再建議放在 application.conf內

    b.需使用play deps 命令才會在這個專案中安裝所需的mudule lib

    c.需使用到非play!所提供的module時,需要放在lib目錄下,需參maven內容,如下說明,maven 片段如下:

    <dependency>
    <groupId>org.springframework.flex</groupId>
    <artifactId>spring-flex-core</artifactId>
    <version>1.5.2.RELEASE</version>
    </dependency>




    在dependencies.yml 使用如下加入


    - org.springframework.flex->spring-flex-core 1.5.2.RELEASE


    - groupId->artifactId version



  5. continue…

2009年5月14日 星期四

二個共同寫一支程式(同時間)

XP(Extreme Programming) 提到的 配對編碼(Pair Programming)
eclipse plug-in Eclipse Communication Framework Project
乎似真能做到二個同共寫一支程式,哪天也來試試二個共同寫一支程式帶來的效益
建議用HD看會比較清楚

Cola: Real-Time Shared Editing from Mustafa K. Isik on Vimeo.