Skip to content

Commit f811006

Browse files
committed
Spring Boot Security MVC WEB MySQL
1 parent aae90b8 commit f811006

File tree

25 files changed

+1459
-46
lines changed

25 files changed

+1459
-46
lines changed

Part-5 Spring Boot Web Application/SpringMultipleDataStructure/src/main/java/spring/mvc/config/OrderDataSourceConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public LocalContainerEntityManagerFactoryBean ordersEntityManagerFactory(){
6565
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
6666
factory.setDataSource(ordersDataSource());
6767
factory.setPackagesToScan(new String[] {
68-
"spring.mvc.orders.repository"
68+
"spring.mvc.orders.entities"
6969
});
7070
factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
7171

@@ -78,7 +78,7 @@ public LocalContainerEntityManagerFactoryBean ordersEntityManagerFactory(){
7878
}
7979

8080
@Bean
81-
public DataSourceInitializer ordersDataSrouceInitializer(){
81+
public DataSourceInitializer ordersDataSourceInitializer(){
8282
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
8383
dataSourceInitializer.setDataSource(ordersDataSource());
8484
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
# # H2 database configuration steps
2-
debug=true
3-
4-
#H2 embedded static database
5-
datasource.security.driver-class-name=org.h2.Driver
6-
7-
# H2 configuration using hibernate.
8-
datasource.security.url=jdbc:h2:mem:management;DB_CLOSE_DELAY=-1
9-
datasource.security.username=sa
10-
datasource.security.password=
11-
12-
# Security configuration on system
13-
datasource.security.initialize=true
14-
15-
# H2 database configuration, using embedded DB
16-
datasource.orders.driver-class-name=org.h2.Driver
17-
datasource.orders.url=jdbc:h2:mem:ordersdb;DB_CLOSE_DELAY=-1
18-
datasource.orders.username=sa
19-
datasource.orders.password=
20-
21-
# Initialize db (any DB types are will be true)
22-
datasource.orders.initialize=true
23-
24-
# Hibernate configuration (auto-update, create.)
25-
spring.jpa.hibernate.ddl-auto=update
26-
27-
# DB represents debuging results.
28-
spring.jpa.show-sql=true
29-
30-
31-
# MySQL database configuration
32-
332
#debug=true
34-
35-
# Database
36-
#datasource.security.driver-class-name=com.mysql.jdbc.Driver
37-
#datasource.security.url=jdbc:mysql://localhost:3306/management
38-
#datasource.security.username=root
39-
#datasource.security.password=posilka2020
403
#
41-
## Secutiry datasource configuration
4+
##H2 embedded static database
5+
#datasource.security.driver-class-name=org.h2.Driver
6+
#
7+
## H2 configuration using hibernate.
8+
#datasource.security.url=jdbc:h2:mem:management;DB_CLOSE_DELAY=-1
9+
#datasource.security.username=sa
10+
#datasource.security.password=
11+
#
12+
## Security configuration on system
4213
#datasource.security.initialize=true
4314
#
44-
## Configuration MySQL
45-
#datasource.orders.driver-class-name=com.mysql.jdbc.Driver
46-
#datasource.orders.url=jdbc:mysql://localhost:3306/ordersdb
47-
#datasource.orders.username=root
48-
#datasource.orders.password=posilka2020
15+
## H2 database configuration, using embedded DB
16+
#datasource.orders.driver-class-name=org.h2.Driver
17+
#datasource.orders.url=jdbc:h2:mem:ordersdb;DB_CLOSE_DELAY=-1
18+
#datasource.orders.username=sa
19+
#datasource.orders.password=
4920
#
21+
## Initialize db (any DB types are will be true)
5022
#datasource.orders.initialize=true
5123
#
24+
## Hibernate configuration (auto-update, create.)
5225
#spring.jpa.hibernate.ddl-auto=update
53-
#spring.jpa.show-sql=true
26+
#
27+
## DB represents debuging results.
28+
#spring.jpa.show-sql=true
29+
30+
31+
# MySQL database configuration
32+
33+
debug=true
34+
35+
Database
36+
datasource.security.driver-class-name=com.mysql.jdbc.Driver
37+
datasource.security.url=jdbc:mysql://localhost:3306/management
38+
datasource.security.username=root
39+
datasource.security.password=posilka2020
40+
41+
# Secutiry datasource configuration
42+
datasource.security.initialize=false
43+
44+
# Configuration MySQL
45+
datasource.orders.driver-class-name=com.mysql.jdbc.Driver
46+
datasource.orders.url=jdbc:mysql://localhost:3306/ordersdb
47+
datasource.orders.username=root
48+
datasource.orders.password=posilka2020
49+
50+
datasource.orders.initialize=true
51+
52+
spring.jpa.hibernate.ddl-auto=update
53+
spring.jpa.show-sql=true
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.net.*;
18+
import java.io.*;
19+
import java.nio.channels.*;
20+
import java.util.Properties;
21+
22+
public class MavenWrapperDownloader {
23+
24+
private static final String WRAPPER_VERSION = "0.5.6";
25+
/**
26+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
27+
*/
28+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
29+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
30+
31+
/**
32+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
33+
* use instead of the default one.
34+
*/
35+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
36+
".mvn/wrapper/maven-wrapper.properties";
37+
38+
/**
39+
* Path where the maven-wrapper.jar will be saved to.
40+
*/
41+
private static final String MAVEN_WRAPPER_JAR_PATH =
42+
".mvn/wrapper/maven-wrapper.jar";
43+
44+
/**
45+
* Name of the property which should be used to override the default download url for the wrapper.
46+
*/
47+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
48+
49+
public static void main(String args[]) {
50+
System.out.println("- Downloader started");
51+
File baseDirectory = new File(args[0]);
52+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
53+
54+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
55+
// wrapperUrl parameter.
56+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
57+
String url = DEFAULT_DOWNLOAD_URL;
58+
if (mavenWrapperPropertyFile.exists()) {
59+
FileInputStream mavenWrapperPropertyFileInputStream = null;
60+
try {
61+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
62+
Properties mavenWrapperProperties = new Properties();
63+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
64+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
65+
} catch (IOException e) {
66+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
67+
} finally {
68+
try {
69+
if (mavenWrapperPropertyFileInputStream != null) {
70+
mavenWrapperPropertyFileInputStream.close();
71+
}
72+
} catch (IOException e) {
73+
// Ignore ...
74+
}
75+
}
76+
}
77+
System.out.println("- Downloading from: " + url);
78+
79+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
80+
if (!outputFile.getParentFile().exists()) {
81+
if (!outputFile.getParentFile().mkdirs()) {
82+
System.out.println(
83+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
84+
}
85+
}
86+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
87+
try {
88+
downloadFileFromURL(url, outputFile);
89+
System.out.println("Done");
90+
System.exit(0);
91+
} catch (Throwable e) {
92+
System.out.println("- Error downloading");
93+
e.printStackTrace();
94+
System.exit(1);
95+
}
96+
}
97+
98+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
99+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
100+
String username = System.getenv("MVNW_USERNAME");
101+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
102+
Authenticator.setDefault(new Authenticator() {
103+
@Override
104+
protected PasswordAuthentication getPasswordAuthentication() {
105+
return new PasswordAuthentication(username, password);
106+
}
107+
});
108+
}
109+
URL website = new URL(urlString);
110+
ReadableByteChannel rbc;
111+
rbc = Channels.newChannel(website.openStream());
112+
FileOutputStream fos = new FileOutputStream(destination);
113+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
114+
fos.close();
115+
rbc.close();
116+
}
117+
118+
}
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

0 commit comments

Comments
 (0)