Wednesday, June 14, 2017

Spring Project Notes

Insert a single-line comment. Comments are designated by the tags <!-- and -->. You can insert quick comments to remind you what is happening with the code. 
<!-- This code makes a paragraph -->




mvn install -> generate "hellop1.war"
tomcat

Spring Boot

Maven Installation

No need to specify version number
<dependencies> <!-- no version needed -->
       <dependency> <!-- including all required dependencies for web development in one place -->
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>

   </dependencies>
<build>
       <plugins>
           <plugin> <!-- fat jar, standalone running enviroment including tomcat-->
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
           </plugin>
       </plugins>

   </build>


[lombok]
no longer need getter() setter()
<dependency>
           <groupId>org.projectlombok</groupId>
           <artifactId>lombok</artifactId>
           <optional>true</optional>

       </dependency>

@Embeddable
可以把这个class作为一个整体塞进数据库里

@Embedded
    @AttributeOverride(name = "engineMake", column = @Column(name = "unit_engine_make"))
    private final UnitInfo unitInfo;

LocationService调用LocationRepository组装成能够向更高层使用的信息


TomCat Port is in use
Run the following command to search for the process that is using the port
lsof -i :<portNumber> | grep LISTEN
in your case this will be -->
lsof -i :8080 | grep LISTEN
java    78960 xyxss  119u  IPv6 0x6c20d372bc88c27d      0t0  TCP *:8092 (LISTEN)
The 78960 is the process id, use the following command to kill the process
kill -9 78960

Launch the application again.


-->Debug
java -jar ./target/fleet-location-service-1.0.0.BUILD-SNAPSHOT.jar 
no main manifest attribute, in ./target/fleet-location-service-1.0.0.BUILD-SNAPSHOT.jar
找不到main manifest

第一次发现是因为错把FleetLocationServiceApplication.class写在了java package下面
而不是java/com.techbow.spring.uber的package下面

reflactor move只有发现问题没有解决,于是如下改动了pom文件
Solution:
//Add these lines into pom.xml
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                ... ...
            </plugin>
        </plugins>
    </build>
-->Debug
运行http://localhost:9000/fleet/vin/3560aa8c-a78f-4a49-a6e7-1c614aab19d1?page=0&size=1的GET请求之后,只返回一行vin,没有整个Location class
这个问题比较好定位 感觉就是JSON在Serilize的时候出了问题
果然看到
Location里面漏了
@JsonInclude(JsonInclude.Include.NON_NULL)

No comments:

Post a Comment