java學習

          java學習

           

          linux mysql 安裝步驟

          1、安裝cmake    (可能需要安裝  yum install gcc-c++)
          2、安裝yum install ncurses-devel -y
          3.創建用戶和組 groupadd mysql
          useradd mysql -s /sbin/nologin -M -g mysql
          4、tar xf mysql-5.5.32.tar.gz
          5、進入MySQL目錄,(可能需要 yum install bison)執行
          cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 -DMYSQL_TCP_PORT=3306
          6、make && make install
          7、cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
          8、添加環境變量   export PATH=/usr/local/mysql/bin:$PATH
          9、授權 chown -R mysql.mysql /usr/local/mysql/data/ 
          10、chmod -R 1777 /tmp/
          11、在MySQL的安裝目錄下的scripts文件夾下,執行./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
          12、負責MySQL啟動命令   cp support-files/mysql.server /etc/init.d/mysqld
          13、授權chmod +x /etc/init.d/mysqld
          14、啟動MySQL    /etc/init.d/mysqld start
          15、查看運行的進程  netstat -lntup|grep 3306
          16、刪除無用的用戶和host,select user,host from mysql.user ;
          刪除test數據庫
          17、刪除root用戶,添加別的數據庫管理員
          delete from mysql.user;
          grant all privileges on *.* to system@'localhost' identified by 'yjw' with grant option;
          /usr/local/mysql//bin/mysqladmin -u root password 'new-password'    --設置密碼
          /usr/local/mysql//bin/mysqladmin -u root -h bogon password 'root'  --修改密碼

          posted @ 2018-04-26 14:02 楊軍威 閱讀(122) | 評論 (0)編輯 收藏

          gtk安裝

          linux下GTK+的一鍵安裝和配置:(fedora16和centos下配置成功)

          必要組件:

           yum install gtk2 gtk2-devel gtk2-devel-docs

          可選組件:

           yum install gnome-devel gnome-devel-docs

          posted @ 2018-04-05 18:06 楊軍威 閱讀(160) | 評論 (0)編輯 收藏

          eclipse linux java in your current PATH

          A Java Runtime Environment (JRE) or Java Development Kit (JDK)
          must be available in order to run Eclipse. No Java virtual machine
          was found after searching the following locations:
          /home/injavawetrust/program/eclipse/jre/bin/java
          java in your current PATH

          解決辦法是在終端進入你的eclipse目錄,然后輸入:

          mkdir jre
          cd jre
          ln -s 你的JDK目錄/bin bin

          posted @ 2018-04-05 17:24 楊軍威 閱讀(1024) | 評論 (0)編輯 收藏

          git 解決 unable to get local issuer certificate 問題

          方法一:

          如果你是用命令行提交的,可以用以下命令設置臨時環境變量GIT_SSL_NO_VERIFY。 
          Windows下:

          set GIT_SSL_NO_VERIFY=true git push
          • 1

          Linux下:

          env GIT_SSL_NO_VERIFY=true git push
          • 1

          設置好之后,然后用Git提交。 
          當然,你也可以把GIT_SSL_NO_VERIFY設置成非臨時環境變量,這樣就不用每次提交都要執行上面的命令了。

          方法二:

          你也可以在命令行執行以下命令,之后再提交。

          git config --global http.sslVerify false
          以上兩個方法,親測有效,建議第二個,直接去掉git的ssl驗證

          posted @ 2018-03-26 10:22 楊軍威 閱讀(10186) | 評論 (0)編輯 收藏

          springcloud中的自定義ribbon客戶端負載均衡配置

          1、不在啟動類同級的包目錄中新建ribbon配置類
          @Configuration
          public class TestConfiguration {
          @Autowired
          IClientConfig config;
            @Bean
            public IRule ribbonRule(IClientConfig config) {
              return new RandomRule();
            }
          }
          在啟動類中添加注解@RibbonClient
          @SpringBootApplication
          @EnableEurekaClient //針對Eureka服務注冊使用
          //@EnableDiscoveryClient  //可以對其他服務注冊軟件使用
          @RibbonClient(name="a-microservice-provider-user",configuration=TestConfiguration.class)
          public class ConsumerMovieRibbonApplication {
          @Bean
          @LoadBalanced//客戶端負載均衡,先把服務提供這所有的節點讀取到ribbon注冊表中,默認輪詢請求服務
          public RestTemplate getRestTemplate() {
          return new RestTemplate();
          public static void main(String[] args) {
          SpringApplication.run(ConsumerMovieRibbonApplication.class, args);
          }
          }
          3.在controller中添加方法
          @GetMapping("/movie/{userid}")
          public TUser test2(@PathVariable(name="userid") String userId) {
          //服務的自動發現,不用配置死的IP和端口,只有在RestTemplate添加了@LoadBalanced接口,才能使用應用名稱訪問
          return restTemplate.getForObject("http://a-microservice-provider-user/users/"+userId, TUser.class);
          }
          4、啟動服務發現服務eureka和服務提供類,調用目標方法,可以成功 調用。

          posted @ 2018-03-21 17:50 楊軍威 閱讀(706) | 評論 (0)編輯 收藏

          springcloud微服務服務發現eureka服務和客戶端服務的搭建

          一、服務端的搭建
          1、在pom文件中添加eureka服務依賴
                          <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-eureka-server</artifactId>
          </dependency>
          <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-security</artifactId>
          </dependency>
          2、編寫application.yml 配置
          security:
            basic:
              enabled: true
            user:
              name: user
              password: password123
          server:
            port: 8761
          eureka:
            client:
              register-with-eureka: false #只把此服務當成eurekaservice,不要當成client
              fetch-registry: false #只把此服務當成eurekaservice,不要當成client
              service-url:
                defaultZone: http://user:password123@localhost:8761/eureka
          3、在啟動類上添加注解
          @SpringBootApplication
          @EnableEurekaServer
          就可以啟動服務發現的服務端程序了。
          二、客戶端的搭建
          1、在pom文件中添加依賴
                      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-eureka</artifactId>
          </dependency>
          2、編寫application.yml 配置
          server:  
            port: 7901  
            session-timeout: 30  
            tomcat.max-threads: 0  
            tomcat.uri-encoding: UTF-8  
            
          spring:  
            application:
              name: a-microservice-consumer-movie
          logging:
            level:
              root: INFO
              com.example.demo: debug
          eureka:
            client:
              serviceUrl:
                defaultZone: http://user:password123@localhost:8761/eureka
                instance: #eureka管理頁面客戶端服務的地址顯示實際IP
                  prefer-ip-address: true   #默認是false
          3、在啟動類添加注解
          @SpringBootApplication
          @EnableEurekaClient //針對Eureka服務注冊使用
          //@EnableDiscoveryClient  //可以對其他服務注冊軟件使用
          這樣客戶端配置完畢,先啟動服務端,再啟動客戶端,服務端就可以自動發現客戶端服務了。
              

          posted @ 2018-03-21 14:09 楊軍威 閱讀(703) | 評論 (0)編輯 收藏

          soringboot項目大war包,部署到Tomcat步驟

          springboot的應用打包默認是打成jar包,并且如果是web應用的話,默認使用內置的tomcat充當servlet容器,但畢竟內置的tomcat有時候并不滿足我們的需求,如有時候我們想集群或者其他一些特性優化配置,因此我們需要把springboot的jar應用打包成war包,并能夠在外部tomcat中運行。
              很多人會疑問,你直接打成war包并部署到tomcat的webapp下不就行了么?No,springboot的如果在類路徑下有tomcat相關類文件,就會以內置tomcat啟動的方式,經過你把war包扔到外置的tomcat的webapp文件下啟動springBoot應用也無事于補。
              要把springboot應用轉至外部tomcat的操作主要有以下三點:
          1、把pom.xml文件中打包結果由jar改成war,如下:
          [html] view plain copy
          1. <modelVersion>4.0.0</modelVersion>  
          2. <groupId>spring-boot-panminlan-mybatis-test</groupId>  
          3. <artifactId>mybatis-test</artifactId>  
          4. <packaging>war</packaging>  
          5. <version>0.0.1-SNAPSHOT</version>  

          2、添加maven的war打包插件如下:并且給war包起一個名字,tomcat部署后的訪問路徑會需要,如:http:localhost:8080/myweb/****

            
          [java] view plain copy
          1. <plugin>       
          2.    <groupId>org.apache.maven.plugins</groupId>       
          3.    <artifactId>maven-war-plugin</artifactId>       
          4.    <configuration>       
          5.     <warSourceExcludes>src/main/resources/**</warSourceExcludes>  
          6.     <warName>myweb</warName>       
          7.    </configuration>       
          8.   </plugin>       

          3、排除org.springframework.boot依賴中的tomcat內置容器,這是很重要的一步

          [java] view plain copy
          1. <dependency>  
          2.         <groupId>org.springframework.boot</groupId>  
          3.         <artifactId>spring-boot-starter-web</artifactId>  
          4.         <exclusions>  
          5.             <exclusion>  
          6.                 <groupId>org.springframework.boot</groupId>  
          7.                 <artifactId>spring-boot-starter-tomcat</artifactId>  
          8.             </exclusion>  
          9.         </exclusions>  
          10.     </dependency>  

          4、添加對servlet API的依賴
          [java] view plain copy
          1. <dependency>  
          2.             <groupId>javax.servlet</groupId>  
          3.             <artifactId>javax.servlet-api</artifactId>  
          4.         </dependency>  

          5、繼承SpringBootServletInitializer ,并覆蓋它的 configure 方法,如下圖代碼,為什么需要提供這樣一個SpringBootServletInitializer子類并覆蓋它的config方法呢,我們看下該類原代碼的注釋:
          /**Note that a WebApplicationInitializer is only needed if you are building a war file and
           * deploying it. If you prefer to run an embedded container then you won't need this at
           * all.
          如果我們構建的是wai包并部署到外部tomcat則需要使用它,如果使用內置servlet容器則不需要,外置tomcat環境的配置需要這個類的configure方法來指定初始化資源。
          [java] view plain co@SpringBootApplication
          //@ServletComponentScan
          public class JobManagementApplication extends SpringBootServletInitializer{

               @Override
          protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
                      return application.sources(JobManagementApplication.class);
                  }
              public static void main(String[] args) {
                  SpringApplication.run(JobManagementApplication.class, args);
              }
          }
          經過以上配置,我們把構建好的war包拷到tomcat的webapp下,啟動tomcat就可以訪問啦

          posted @ 2018-03-17 18:39 楊軍威 閱讀(662) | 評論 (0)編輯 收藏

          soringboot熱部署配置

          在pom文件中加入
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-devtools</artifactId>
              <optional>true</optional>
              <scope>true</scope> 
          </dependency>


           <plugin>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-maven-plugin</artifactId>
                      <configuration>
                          <fork>true</fork>
                      </configuration>
                  </plugin>



          posted @ 2018-03-15 14:40 楊軍威 閱讀(153) | 評論 (0)編輯 收藏

          在springboot中fastjson的配置

          第一種配置方法:
          在實體類中加入格式化屬性的注解
          public class User implements Serializable{
          /**
          */
          private static final long serialVersionUID = 1L;
          private Integer id;
          private String username;
          private Date birthday;
          private Integer age;
          public Integer getId() {
          return id;
          }
          public void setId(Integer id) {
          this.id = id;
          }
          @JSONField(format="yyyy-MM-dd hh:MM:ss")
          public Date getBirthday() {
          return birthday;
          }
          public void setBirthday(Date birthday) {
          this.birthday = birthday;
          }
          public String getUsername() {
          return username;
          }
          public void setUsername(String username) {
          this.username = username;
          }
          public Integer getAge() {
          return age;
          }
          public void setAge(Integer age) {
          this.age = age;
          }
          2.在啟動類中繼承類
          @SpringBootApplication
          public class Demo1Application2 extends WebMvcConfigurerAdapter{
          @Override
          public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
          super.configureMessageConverters(converters);
          FastJsonHttpMessageConverter fastConverter=new  FastJsonHttpMessageConverter();
          FastJsonConfig fastJsonConfig = new FastJsonConfig();
          fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
          fastConverter.setFastJsonConfig(fastJsonConfig);
          converters.add(fastConverter);
          }
          public static void main(String[] args) {
          SpringApplication app=new SpringApplication(Demo1Application2.class);
          ConfigurableApplicationContext context = app.run( args);
          //context.close();
          }
          }
          3.訪問頁面,請求方法,得到結果
          { "age":11, "birthday":"2018-03-15 10:03:55", "id":1, "username":"dddd" }
          第二種配置方法:
          在啟動類加入一個bean
          @SpringBootApplication
          public class Demo1Application3 {
          @Bean
          public HttpMessageConverters fastJsonHttpMessageConverters() {
          FastJsonHttpMessageConverter fastConverter=new  FastJsonHttpMessageConverter();
          FastJsonConfig fastJsonConfig = new FastJsonConfig();
          fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
          fastConverter.setFastJsonConfig(fastJsonConfig);
          HttpMessageConverter<?> converters=fastConverter;
          return new HttpMessageConverters(converters);
          }
          public static void main(String[] args) {
          SpringApplication app=new SpringApplication(Demo1Application3.class);
          ConfigurableApplicationContext context = app.run( args);
          //context.close();
          }
          }

          posted @ 2018-03-15 10:36 楊軍威 閱讀(1186) | 評論 (0)編輯 收藏

          利用BeanPostProcessor接口實現bean初始化的前后執行方法

          1、aop的簡單實現
          public class User implements InitializingBean,DisposableBean{
          public String toString() {
          System.out.println("userdddd");
          return "444";
          }
          @Override
          public void afterPropertiesSet() throws Exception {
          System.out.println(" user afterPropertiesSet");
          }
          @Override
          public void destroy() throws Exception {
          System.out.println("user destroy");
          }
          }
          public class LogUser extends User{
          public String toString() {
          System.out.println("log start");
          super.toString();
          System.out.println("log end");
          return "";
          }
          }
          public interface MyApplicationContextAware {
          void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
          }
          @Component
          public class Dog4 implements MyApplicationContextAware{
          ApplicationContext applicationContext;
          public ApplicationContext getApplicationContext() {
          return applicationContext;
          }
          @Override
          public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
          this.applicationContext=applicationContext;
          }
          }
          @Component
          public class MyBeanPostProcessor implements BeanPostProcessor{
          @Autowired
          ApplicationContext applicationContext;
          @Override
          public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
          System.out.println("postProcessAfterInitialization=="+beanName);
          return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
          }
          @Override
          public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
          System.out.println("postProcessBeforeInitialization=="+beanName);
          if(bean instanceof User) {
          return new LogUser();
          }
          if(bean instanceof MyApplicationContextAware) {
          MyApplicationContextAware my=(MyApplicationContextAware) bean;
          my.setApplicationContext(applicationContext);
          }
          return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
          }
          }
          public class App {
          public static void main(String[] args) {
          AnnotationConfigApplicationContext aa=new AnnotationConfigApplicationContext("com.yjw");
          Dog4 dog = aa.getBean(Dog4.class);
          System.out.println(dog.getApplicationContext());
          User user = aa.getBean(User.class);
          System.out.println(user.toString());
          aa.close();
          }
          }

          posted @ 2018-03-06 15:34 楊軍威 閱讀(471) | 評論 (0)編輯 收藏

          僅列出標題
          共43頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 咸宁市| 乐东| 酒泉市| 武邑县| 广平县| 县级市| 安徽省| 绥宁县| 琼结县| 昌吉市| 洪泽县| 杭锦后旗| 宁远县| 万盛区| 新乡市| 墨竹工卡县| 深泽县| 原平市| 乌拉特前旗| 河西区| 永城市| 彰武县| 视频| 金阳县| 梨树县| 四平市| 喜德县| 宣化县| 永平县| 南靖县| 廊坊市| 玉环县| 稷山县| 仪征市| 濉溪县| 章丘市| 亚东县| 景宁| 沙河市| 康保县| 丰台区|