使用无参构造创建对象,默认!
使用有参构造创建对象
<!--第一种 下标赋值-->
<bean id="user" class="com.jan.pojo.User">
<constructor-arg index="0" value="钟健"/>
</bean>
类型创建
<!--第二种 通过类型创建 不建议使用-->
<bean id="user" class="com.jan.pojo.User">
<constructor-arg type="java.lang.String" value="zhongjian"/>
</bean>
参数名
<!-- 第三种 直接通过参数名来设置-->
<bean id="user" class="com.jan.pojo.User">
<constructor-arg name="name" value="Jan"/>
</bean>
总结:在配置文件加载的时候,容器中的管理的对象就已经初始化了!
<!--别名,如果添加了别名,我们也可以使用别名取到这个对象-->
<alias name="user" alias="userNew"/>
<!--
id: bean 的唯一标识符,也就是相当于我们学的对象名
class: bean 对象所对应的全限定名: 包名 + 类型
name: 也是别名, 而且name 可以同时取多个别名
-->
<bean id="userT" class="com.jan.pojo.UserT" name="user2 u2,u3;u4">
<property name="name" value="钟健学习"/>
</bean>
这个import一般用于团队开发使用,他可以将多个配置文件导入合并为一个,假设,现在项目有对人开发,将三人不同的开类需注册到不同的bean中,我们可以利用import将所有人的beans.xml合并为一个总的!
张三
李四
王五
applicationContext
<import resource="beans.xml"/>
<import resource="beans2.xml"/>
<import resource="beans3.xml"/>
【环境搭建】
复杂类型
public class Address {
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
真实测试对象
public class Student {
private String name;
private Address address;
private String[] books;
private List<String>hobbys;
private Map<String,String> card;
private Set<String> games;
private String wife;
private Properties info;
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="student" class="com.jan.pojo.Student">
<!--第一种,普通注入,value-->
<property name="name" value="钟健"/>
</bean>
</beans>
测试类
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Student student = (Student) context.getBean("student");
System.out.println(student.getName());
}
}
完善注入信息
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="address" class="com.jan.pojo.Address">
<property name="address" value="北京"/>
</bean>
<bean id="student" class="com.jan.pojo.Student">
<!--第一种,普通注入,value-->
<property name="name" value="钟健"/>
<!--第二种,bean注入,ref-->
<property name="address" ref="address"/>
<!--数组注入-->
<property name="books">
<array>
<value>红楼梦</value>
<value>水浒传</value>
<value>三国演义</value>
<value>西游记</value>
</array>
</property>
<!--List-->
<property name="hobbys">
<list>
<value>听歌</value>
<value>敲代码</value>
<value>看电影</value>
</list>
</property>
<!--Map-->
<property name="card">
<map>
<entry key="身份证" value="111111222222223333"/>
<entry key="银行卡" value="123456789"/>
</map>
</property>
<!--Set-->
<property name="games">
<set>
<value>LOL</value>
<value>COS</value>
</set>
</property>
<!--null-->
<property name="wife">
<null/>
</property>
<!--Properties-->
<property name="info">
<props>
<prop key="driver">20230102</prop>
<prop key="url">男</prop>
<prop key="username">root</prop>
<prop key="password">123456</prop>
</props>
</property>
</bean>
</beans>
5.2、Set方式注入【重点】
我们可以使用P命名空间和C 命名空间进行注入
官方解释

使用
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- P命名空间注入,可以直接注入属性的值 property-->
<bean id="user" class="com.jan.pojo.User" p:name="钟健" p:age="18"/>
<!-- c命名空间注入,通过构造器注入 construct-args-->
<!--在User类中要有无参和有参构造器才可以使用 C 命名注入-->
<bean id="user2" class="com.jan.pojo.User" c:age="18" c:name="Jan"/>
</beans>
测试
@Test
public void test2(){
ApplicationContext context = new ClassPathXmlApplicationContext("userbeans.xml");
//User user = context.getBean("user", User.class);
User user = context.getBean("user2", User.class);
System.out.println(user);
}
注意点: P 命名和 C 命名空间不能直接使用,需要导入xml约束!
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"

单例模式(Spring默认机制)--->30分钟的教学记得看
<bean id="user2" class="com.jan.pojo.User" c:age="18" c:name="Jan" scope="singleton"/>
原型模式:每次从容器中get的时候,都会产生一个新对象!
<bean id="user2" class="com.jan.pojo.User" c:age="18" c:name="Jan" scope="prototype"/>
其余的request、session、application,这些个只能在web开发中使用的!
在spring的三种配置方式:
环境搭建:一个人有两个宠物!
<bean id="cat" class="com.jan.pojo.Cat"/>
<bean id="dog" class="com.jan.pojo.Dog"/>
<bean id="people" class="com.jan.pojo.People">
<property name="name" value="钟健"/>
<property name="cat" ref="cat"/>
<property name="dog" ref="dog"/>
</bean>
<bean id="cat" class="com.jan.pojo.Cat"/>
<bean id="dog" class="com.jan.pojo.Dog"/>
<!--
ByName: 会自动在容器上下文中查找,和自己对象set方法后面的值对应的 bean id!
ByType: 会自动在容器上下文中查找,和自己对象属性类型相同的 bean !
-->
<bean id="people" class="com.jan.pojo.People" autowire="byName">
<property name="name" value="钟健"/>
</bean>
<bean class="com.jan.pojo.Cat"/>
<bean class="com.jan.pojo.Dog"/>
<!--
ByName: 会自动在容器上下文中查找,和自己对象set方法后面的值对应的 bean id!
ByType: 会自动在容器上下文中查找,和自己对象属性类型相同的 bean !
-->
<bean id="people" class="com.jan.pojo.People" autowire="byType">
<property name="name" value="钟健"/>
</bean>
小结:
jdk1.5支持的注解,Spring2.5就支持注解了!
The introduction of annotation-based configuration raised the question of whether this approach is “better” than XML.
要使用注解须知:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
</beans>
@Autowired
直接在属性上使用即可!也可以在set方式上使用!
使用Autowired 我们可以不用编写Set方法了,前提式你这个自动装配的属性在IOC(Spring)容器中存在,且符合名字byname!
科普:
@Nullable 字段标记了这个注解,说明了这个字段可以为null;
public People(@Nullable String name) {
this.name = name;
}
public @interface Autowired {
boolean required() default true;
}
测试代码
public class People {
//如果显示定义了Aurowired的required的属性为false,说明这个对象可以为null,否则不允许为空!
@Autowired(required = false)
private Cat cat;
@Autowired
private Dog dog;
private String name;
}
如果 @Autowired 自动装配的环境比较复杂,自动装配无法通过一个注解【@Autowired】完成的时候,我们可以谁用@Qualifier(value == "xxx")去配置@Autowired的使用,指定一个唯一的bean对象注入!
public class People {
@Autowired
@Qualifier(value = "cat222")
private Cat cat;
@Autowired
@Qualifier(value = "dog222")
private Dog dog;
private String name;
}
xml的代码
<bean id="cat222" class="com.jan.pojo.Cat"/>
<bean id="cat111" class="com.jan.pojo.Cat"/>
<bean id="dog222" class="com.jan.pojo.Dog"/>
<bean id="dog111" class="com.jan.pojo.Dog"/>
<bean id="people" class="com.jan.pojo.People" />
@Resource注解
public class People {
@Resource(name = "cat2")
private Cat cat;
@Resource
private Dog dog;
}
小结:
@Autowired和@Resource的区别:
在Spring4之后,要使用注解开发,必须要保证aop包的注入!

使用注解需要导入context约束,增加注解的支持!
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
</beans>
bean
属性如何注入
//等价于 <bean id="user" class="com.jan.pojo.User"/>
//@Component 组件
@Component
public class User {
public String name ;
//相当于 <property name="name" value="zhongjian"/>
@Value("zhongjian")
public void setName(String name) {
this.name = name;
}
}
衍生的注解
@Component有几个衍生注解,我们在web开发中,会按照mvc三层架构分层!
dao 【@Repository】
service 【@Service】
controller 【@Controller】
这四个注解功能都是一样的,都是代表将某个类注册到Spring中,装配Bean。
自动装配置
- @Autowired:自动装配,通过属性,名字
如果Autowired不能唯一自动装配上属性,则需要通过@Qualifier(value == "xxx")
- @Nullable 字段标记了这个注解,说明了这个字段可以为null;
- @Resource:自动装配,通过名字,属性
作用域
@Scope("prototype")
@Scope("singleton")
@Component
@Scope("prototype")
public class User {
public String name ;
//相当于 <property name="name" value="zhongjian"/>
@Value("zhongjian")
public void setName(String name) {
this.name = name;
}
}
小结
xml与注解:
xml与注解最佳实践:
xml用来管理bean;
注解只负责完成属性的注入;、
我们在使用的过程中,只需要注意一个问题:必须让注解生效,就需要开启注解的支持
<!-- 指定要扫描的包,这个包下的注解就会生效 -->
<context:component-scan base-package="com.jan.pojo"/>
<context:annotation-config/>
我们现在要完全不适用Spring 的 xml 配置了,全权交给Java来做!
JavaConfig 是 Spring 的一个字项目,在 Spring 4之后, 它成为了一个核心功能!

实体类
package com.jan.pojo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
//这个注解的意思,就是说明这个类被Spring接管了,注册到了容器中
@Component
public class User {
private String name;
public String getName() {
return name;
}
@Value("ZHONGJIAN") //属性注入值
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
'}';
}
}
配置文件
package com.jan.config;
import com.jan.pojo.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
//这个也是Spring容器托管,注册到容器中,因为它本来就是一个@Component
//@Configuration代表这是一个配置类,就和 我们之前看到的beans.xml
@Configuration
@ComponentScan("com.jan.pojo")
@Import(JanConfig2.class)
public class JanConfig {
//注册一个Bean,就相当于我们之前写的一个bean标签
//这个方法的名字(eg:user),就相当于bean标签中的id属性
//这个方法的返回值(eg:User),就相当于bean标签中的class属性
@Bean
public User user(){
return new User(); // 就是返回要注入到bean的对象!
}
}
测试类
public class MyTest {
public static void main(String[] args) {
//如果完全使用了配置类的方式去做,我们就只能通过 AnnotationConfig 上下文来获取容器,通过配置类的class对象加载!
ApplicationContext context = new AnnotationConfigApplicationContext(JanConfig.class);
User getUser = context.getBean("user", User.class);
System.out.println(getUser.getName());
}
}
这种纯Java的配置方式,在SpringBoot中随处可见!
为什么 要学习代理模式?因为这就是SpringAOP的底层! 【SpringAOP和SpringMVC】
代理模式的分类:
角色分析:
代码步骤:
接口
//租房这件事情
public interface Rent {
public void rent();
}
真实角色
//房东
public class Host implements Rent{
public void rent() {
System.out.println("房东要出租房子!");
}
}
代理角色
package com.jan.demo01;
//代理
public class Proxy implements Rent{
private Host host;
public Proxy() {
}
public Proxy(Host host) {
this.host = host;
}
public void rent() {
host.rent();
seeHouse();
contract();
fare();
}
//看房
public void seeHouse(){
System.out.println("中介带你去看房");
}
//签合同
public void contract(){
System.out.println("签租赁合同");
}
//收中介费
public void fare(){
System.out.println("收中介费");
}
}
客户端访问代理角色
package com.jan.demo01;
//房客
public class Client {
public static void main(String[] args) {
//房东要出租房子
Host host = new Host();
//代理角色,中介帮房租出租房子,但是呢?代理角色一般会有一些附属操作!
Proxy proxy = new Proxy(host);
//你不用面对房东,直接找中介租房子即可!
proxy.rent();
}
}
代理模式的好处:
缺点:
对原来项目的基础上新增加一个方法,使用代理模式。若是在原代码上修改,万一出错,会造成不可估量的损失。
原项目:
接口
public interface UserService {
public void add();
public void delete();
public void update();
public void query();
}
真实对象
//真实对象
public class UserServiceImpl implements UserService{
public void add() {
System.out.println("增加了一个用户");
}
public void delete() {
System.out.println("删除了一个用户");
}
public void update() {
System.out.println("修改了一个用户");
}
public void query() {
System.out.println("查询了一个用户");
}
}
客户端
//客户端 实现方法
public class Client {
public static void main(String[] args) {
//真实角色
UserServiceImpl userService = new UserServiceImpl();
userService.add();
}
}
现在原来的项目上,使用了啥方法,就新增输出:利用了啥方法【运用代理模式】
代理角色
package com.jan.demo02;
public class UserServiceProxy implements UserService {
//引用接口
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
public void add() {
log("add");
userService.add();
}
public void delete() {
log("delete");
userService.delete();
}
public void update() {
log("update");
userService.update();
}
public void query() {
log("query");
userService.query();
}
//日志方法
public void log(String msg){
System.out.println("[Debug]使用了"+msg+"方法");
}
}
客户端访问代理角色
package com.jan.demo02;
//客户端 实现方法
public class Client {
public static void main(String[] args) {
//真实角色
UserServiceImpl userService = new UserServiceImpl();
//代理角色
UserServiceProxy proxy = new UserServiceProxy();
proxy.setUserService(userService);
proxy.add();
}
}
需要了解两个类: Proxy :代理; InvocationHandler:调用处理程序
动态代理的好处:
可以使真是角色的操作更加纯粹!不用去关注一些公共的业务
公共业务也就交给代理角色!实现了业务的分工!
公共业务发生扩展的时候,方便集中管理!
一个动态代理类代理的是一个接口,一般就是对应的一类的业务
一个动态代理类可以代理多个类,只要是实现了同一个接口
代码步骤:
接口
package com.jan.demo03;
//租房这件事情
public interface Rent {
public void rent();
}
真实对象
package com.jan.demo03;
//房东
public class Host implements Rent {
public void rent() {
System.out.println("房东要出租房子!");
}
}
动态代理
package com.jan.demo03;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//等我们会用这个类,自动生成代理类!
public class ProxyInvocationHandler implements InvocationHandler {
//被代理的接口
private Rent rent;
public void setRent(Rent rent) {
this.rent = rent;
}
//生成得到代理类
public Object getProxy(){
return Proxy.newProxyInstance(this.getClass().getClassLoader(),
rent.getClass().getInterfaces(),this );
}
//处理代理实例,并返回结果
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//动态代理的本质就是使用反射机制实现!
seeHouse();
Object result = method.invoke(rent, args);
fare();
return result;
}
public void seeHouse(){
System.out.println("中介带看房子");
}
public void fare(){
System.out.println("收中介费");
}
}
客户端访问动态代理
package com.jan.demo03;
import java.lang.reflect.InvocationHandler;
public class Client {
public static void main(String[] args) {
//真实角色
Host host = new Host();
//代理角色,现在还没有
ProxyInvocationHandler pih = new ProxyInvocationHandler();
//通过调用程序处理角色,来处理我们要调用的接口对象!
pih.setRent(host);
Rent proxy = (Rent) pih.getProxy();//这里的proxy就是动态生成的,我们并没有写!
proxy.rent();
}
}
实际动态代理的模板计较固定,可修改为通用的模板,然后再修改(target)
package com.jan.demo04;
import com.jan.demo03.Rent;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//等我们会用这个类,自动生成代理类!
public class ProxyInvocationHandler implements InvocationHandler {
//被代理的接口
private Object target;
public void setTarget(Object target) {
this.target = target;
}
//生成得到代理类
public Object getProxy(){
return Proxy.newProxyInstance(this.getClass().getClassLoader(),
target.getClass().getInterfaces(),this );
}
//处理代理实例,并返回结果:
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//动态代理的本质就是使用反射机制实现!
Object result = method.invoke(target, args);
return result;
}
}
根据demo02的UserServiceImpl进行修改
客户端
package com.jan.demo04;
import com.jan.demo02.UserService;
import com.jan.demo02.UserServiceImpl;
public class Client {
public static void main(String[] args) {
//真实角色
UserServiceImpl userService = new UserServiceImpl();
//代理角色,不存在
ProxyInvocationHandler pih = new ProxyInvocationHandler();
pih.setTarget(userService);//设置要代理的对象,即真实角色的名字
//动态生成代理类
UserService proxy = (UserService) pih.getProxy();
proxy.query();
}
}
动态代理
package com.jan.demo04;
import com.jan.demo03.Rent;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//等我们会用这个类,自动生成代理类!
public class ProxyInvocationHandler implements InvocationHandler {
//被代理的接口
private Object target;
public void setTarget(Object target) {
this.target = target;
}
//生成得到代理类
public Object getProxy(){
return Proxy.newProxyInstance(this.getClass().getClassLoader(),
target.getClass().getInterfaces(),this );
}
//处理代理实例,并返回结果:
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//动态代理的本质就是使用反射机制实现!
log(method.getName());
Object result = method.invoke(target, args);
return result;
}
public void log(String msg){
System.out.println("执行了"+msg+"方法");
}
}
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在