-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from AwakenCN/springboot
修改1.1.3版本bean注入失败问题
- Loading branch information
Showing
15 changed files
with
248 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/github/unclecatmyself/common/utils/SpringContextUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.github.unclecatmyself.common.utils; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by MySelf on 2019/8/20. | ||
*/ | ||
@Component | ||
public class SpringContextUtils implements ApplicationContextAware { | ||
|
||
/** | ||
* 上下文对象实例 | ||
*/ | ||
private static ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
} | ||
|
||
/** | ||
* 获取applicationContext | ||
* | ||
* @return | ||
*/ | ||
public static ApplicationContext getApplicationContext() { | ||
return applicationContext; | ||
} | ||
|
||
/** | ||
* 通过name获取 Bean. | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
public static Object getBean(String name) { | ||
return getApplicationContext().getBean(name); | ||
} | ||
|
||
/** | ||
* 通过class获取Bean. | ||
* | ||
* @param clazz | ||
* @param <T> | ||
* @return | ||
*/ | ||
public static <T> T getBean(Class<T> clazz) { | ||
return getApplicationContext().getBean(clazz); | ||
} | ||
|
||
/** | ||
* 通过name,以及Clazz返回指定的Bean | ||
* | ||
* @param name | ||
* @param clazz | ||
* @param <T> | ||
* @return | ||
*/ | ||
public static <T> T getBean(String name, Class<T> clazz) { | ||
return getApplicationContext().getBean(name, clazz); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/github/unclecatmyself/task/TextData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.unclecatmyself.task; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by MySelf on 2019/8/20. | ||
*/ | ||
public abstract class TextData { | ||
|
||
public abstract void writeData(Map<String,Object> maps); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/github/unclecatmyself/users/UserTextData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.unclecatmyself.users; | ||
|
||
import com.github.unclecatmyself.common.utils.SpringContextUtils; | ||
import com.github.unclecatmyself.task.TextData; | ||
import com.github.unclecatmyself.users.pojo.Test; | ||
import com.github.unclecatmyself.users.repository.TestRepository; | ||
import org.apache.catalina.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by MySelf on 2019/8/20. | ||
*/ | ||
public class UserTextData extends TextData { | ||
|
||
private TestRepository repository = (TestRepository) SpringContextUtils.getBean(TestRepository.class); | ||
|
||
@Override | ||
public void writeData(Map<String, Object> maps) { | ||
Test test = new Test(); | ||
test.setId(1); | ||
test.setMsg("1111"); | ||
repository.save(test); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/unclecatmyself/users/pojo/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.unclecatmyself.users.pojo; | ||
|
||
import lombok.Data; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* @ClassName TestUser | ||
* @Description 框架测试用户,测试密码加密,不允许生产使用 | ||
* @Author MySelf | ||
* @Date 2019/7/27 11:06 | ||
* @Version 1.0 | ||
**/ | ||
@Entity | ||
@Data | ||
@DynamicUpdate | ||
public class Test implements Serializable { | ||
|
||
/**id*/ | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
/**信息*/ | ||
private String msg; | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/github/unclecatmyself/users/repository/TestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.unclecatmyself.users.repository; | ||
|
||
import com.github.unclecatmyself.users.pojo.Test; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* @InterfaceName TestUserRepository | ||
* @Description Jpa映射层 | ||
* @Author MySelf | ||
* @Date 2019/7/27 11:05 | ||
* @Version 1.0 | ||
**/ | ||
public interface TestRepository extends JpaRepository<Test,Integer> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
spring: | ||
datasource: | ||
driver-class-name: com.mysql.jdbc.Driver | ||
url: jdbc:mysql://192.168.192.133:3306/inchat | ||
username: root | ||
password: password | ||
jpa: | ||
show-sql: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spring: | ||
profiles: | ||
active: dev |
File renamed without changes.