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 杨军威 阅读(116) | 评论 (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 杨军威 阅读(152) | 评论 (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 杨军威 阅读(1009) | 评论 (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 杨军威 阅读(10145) | 评论 (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 杨军威 阅读(694) | 评论 (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 杨军威 阅读(698) | 评论 (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 杨军威 阅读(643) | 评论 (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 杨军威 阅读(147) | 评论 (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 杨军威 阅读(1163) | 评论 (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 杨军威 阅读(464) | 评论 (0)编辑 收藏

仅列出标题
共43页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜