質問編集履歴
2
サンプルプログラム追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
コード
|
1
|
-
@Autowiredを使うことが出来ません。
|
3
|
+
```@Autowiredを使うことが出来ません。
|
2
4
|
すべてのクラスの同じpackageに入れて@Autowiredを使用しても下記のエラー文が出力されてプログラムが実行できません。
|
3
5
|
@ComponentScanを使用しても変わりません。
|
4
6
|
|
@@ -61,4 +63,28 @@
|
|
61
63
|
|
62
64
|
|
63
65
|
}
|
64
|
-
```
|
66
|
+
```
|
67
|
+
以下、動作確認で作ったソースです。
|
68
|
+
```java
|
69
|
+
@Controller
|
70
|
+
public class MemoController {
|
71
|
+
|
72
|
+
@Autowired
|
73
|
+
CustomerService cumser;
|
74
|
+
|
75
|
+
@RequestMapping("/")
|
76
|
+
public String memo(){
|
77
|
+
cumser.aaa();
|
78
|
+
return "MemoView";
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
@Service
|
83
|
+
@Transactional
|
84
|
+
public class CustomerService{
|
85
|
+
//ためし
|
86
|
+
public void aaa(){
|
87
|
+
|
88
|
+
System.out.println("できたー");
|
89
|
+
}
|
90
|
+
}```
|
1
CustomerRepositoryクラスの追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
SpringFrameworkのAutowiredについて
|
1
|
+
SpringFrameworkのAutowiredのエラーについて
|
body
CHANGED
@@ -43,4 +43,22 @@
|
|
43
43
|
|
44
44
|
Consider defining a bean of type 'soturon.CustomerRepository' in your configuration.
|
45
45
|
|
46
|
+
```
|
47
|
+
申し訳ありません。以下CustomerRepositoryクラスになります。
|
48
|
+
```java
|
49
|
+
package soturon;
|
50
|
+
|
51
|
+
import java.util.List;
|
52
|
+
|
53
|
+
import org.springframework.data.jpa.repository.JpaRepository;
|
54
|
+
import org.springframework.data.jpa.repository.Query;
|
55
|
+
|
56
|
+
public interface CustomerRepository extends JpaRepository<Customer, Integer> {
|
57
|
+
|
58
|
+
@Query("SELECT * FROM customer")
|
59
|
+
List<Customer> findAllOrderByName();
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
}
|
46
64
|
```
|