/** * TODO 自定义JobFactory, 为了注入jobInstance中的@Autowired@Resource等实例 * Created by jinzili on 25/09/2017. */ @Component publicclassSpringJobFactoryConfigextendsAdaptableJobFactory{
在Sprint Data JPA中默认提供了许多CRUD方法,基本上单表操作已经完全够用了,但是在开发过程中发现使用nativeQuery不能和pageable共用,例如
1 2
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1", nativeQuery = true) Page<User> findByEmailAddress(String emailAddress, Pageable pageable);
此时项目启动时会报:
1
org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException: Cannot use native queries with dynamic sorting and/or pagination in method
意思就是同一个方法中native queries 不能和 sorting、pagination共用。 但是这种需求却是实实在在的存在的,查看Spring Data JPA官方文档,给出了一下解决方式:
1 2 3 4
@Query(value = "SELECT * FROM USERS WHERE LASTNAME = ?1", countQuery = "SELECT count(*) FROM USERS WHERE LASTNAME = ?1", nativeQuery = true) Page<User> findByLastname(String lastname, Pageable pageable);
使用此方式后依然报上文的exception,查阅其他资料后使用如下方式解决:
1 2
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1 \n#pageable\n", nativeQuery = true) Page<User> findByEmailAddress(String emailAddress, Pageable pageable);
# Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
# Configuration to deploy release version of the Dashboard UI compatible with # Kubernetes 1.6 (RBAC enabled). # # Example usage: kubectl create -f <this_file>
apiVersion: v1 kind: ServiceAccount metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: kubernetes-dashboard labels: app: kubernetes-dashboard roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system --- kind: Deployment apiVersion: extensions/v1beta1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: kubernetes-dashboard template: metadata: labels: app: kubernetes-dashboard spec: containers: - name: kubernetes-dashboard image: registry.cn-beijing.aliyuncs.com/bbt_k8s/kubernetes-dashboard-amd64:v1.6.0 imagePullPolicy: Always ports: - containerPort: 9090 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. # - --apiserver-host=http://my-address:port livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 serviceAccountName: kubernetes-dashboard # Comment the following tolerations if Dashboard must not be deployed on master tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule --- kind: Service apiVersion: v1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 80 targetPort: 9090 selector: app: kubernetes-dashboard
[root@kube-master manifests]# kubectl create -f dashboard-rbac.yaml clusterrolebinding "dashboard-admin" created [root@kube-master manifests]# kubectl create -f dashboard.yaml serviceaccount "kubernetes-dashboard" created clusterrolebinding "kubernetes-dashboard" created deployment "kubernetes-dashboard" created service "kubernetes-dashboard" created
查询dashboard运行的端口
1
kubectl describe --namespace kube-system service kubernetes-dashboard
kubeadm reset ifconfig cni0 down ip link delete cni0 ifconfig flannel.1 down ip link delete flannel.1 rm -rf /var/lib/cni/
不出意外Master Node 已初始化成功。此时查看节点状态 kubectl get nodes 会报 The connection to the server localhost:8080 was refused - did you specify the right host or port? 我们查看kube-apiserver的监听端口